Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to C#

Status
Not open for further replies.

petperson

Programmer
Oct 2, 2002
106
US
Hi,

I am learning C# and would like some advice from the 'experts'. I am having some trouble with the layout, ie naming of classes, etc. I was told to give classes a logical name, ie. Customer - but then how do you typically name the class which contains the main() method? I was naming this class as 'Customer' but then found I needed an another customer class later on. Does someone have a logical naming convention that helps keep things orderly and easy to follow? ALso, do you always keep the class with the main method last in the code?

It's some of the simple things that are confusing me in the beginning!

Thanks in advance.
 
petperson,
What kind of application are you trying to create?

Normally, you should put your classes together in a separate file, (or a separate project) from the class which will be using it.

This way, you could make a dll containing your classes and use that dll with any project later on. Also, your classes won't need a main() method because that method should be in the project that's using them.
You can have something like this:

Project 1 - PetPersonClasses (dll)
Customer
Invoice
...

Project 2 - ClassTester (Windows/Console app)
the class with your main method goes here.
This will most likely be a Windows or Console
application


Hope this helps!

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
Thanks JCruz -

I am working on a console application. Your suggestion makes sense, however i am not sure how to create a dll nor how I would reference it in my 'ClassTester' project.

p.p.
 
petperson,
Well, it's actually quite simple.

Assuming that you're using Visual Studio .NET, what you want to do is this:

1 - Create a C# project of type "Console Application". You have already done this.

2 - On the file menu, select New >> Project. This time, the project type should be "Class Library". Give the new project a name and make sure you select the option that says "Add to solution". This way, both projects will be in the solution and you'll be able to work with the two of them at once.

3 - You must then add a reference of the Class Library project to the Console app project. To do this, on the Solution Explorer, right click the Console app project and click on "Add reference...". This will bring up the add references form, which contains different tabs. Click on the Project tab and select the Class Library project that you have just added to the solution.

4 - On the Console app code, add a "using" statement to add the namespace of the Class Library to the console app project.

And you're done! Add classes to the Class Library project and simply use them in the Console App one.

You may find answers to questions like these (and many more) at the MSDN Library.

Hope this helps!

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
OK - I understand!

Yes, the suggestions help. I have been looking at the MSDN library. Thank you so much. I will continue prodding through this stuff although it tends to boggle the mind at times!

p.p.
 
I think creating dll's may be a little advanced for a beginner. It is perfectly acceptable to have multiple classes in the same project.
 
RiverGuy,
I'm aware that multiple classes can coexist in the same project (and even the same file), and I apologize if my reply sounded as if I meant to say otherwise. petperson is not new to programming, however. He's just new to C#, and the concept of dlls shouldn't be a problem for him.

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top