Click here to Skip to main content
15,942,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using c# for over 3 months now and I still think that my codes are still immature, meaning codes for a beginner.
I want to raise my level of coding and enhance my code.

I have a few questions like:
-when to use camelCase and PascalCase?
-what prefixes should I use?
-how to create/dispose objects?
-and such that will help improve my coding...

Do you guys have any ideas/suggestions.

Thanks in advance.

Share this answer
thatraja 20-Jul-11 3:07am    
Right, 5!
Use camel case for stack variables, pascal case otherwise. Some use camel case also for private members of a type. Don't use underscore, too short names. For more detail, see Microsoft naming conventions. Install FxCop to review your naming, see[^]. Use common sense. Names should be semantic. A label should not be called Label1, application name should not contain word "App" or "Application", a class name should not contain the word "Class", etc.

No prefixes.

There are few ways of creating objects: calling a constructor with "new" or a static factory method returning created object (used to hide constructor or create a derived object my the method of abstract base class). The art is not creating objects but creating constructors and factory methods.
You need and should dispose only the objects implementing the interface IDisposable. There are two basic patterns: using "using" construct and hierarchy of objects (for example, see System.Windows.Forms.Form.Dispose(Boolean),[^]. For the pattern with "using" see[^], use it whenever possible instead of manually calling Dispose().

If by "disposing" you mean deletion of the object, in .NET the Garbage Collector (GC) takes care of it. Read this:[^]. As you cannot rely on the moment of deletion of the object, the rule of thumb is: do not write destructors. There are exclusions though.

"And such that will help improve my coding" makes the question way to broad. This is lifetime experience.

Share this answer
thatraja 20-Jul-11 3:07am    
Excellent, 5!
Sergey Alexandrovich Kryukov 20-Jul-11 3:10am    
Thank you, Raja.
unknowndentified10111 20-Jul-11 5:43am    
Superb.. Thanks..
Sergey Alexandrovich Kryukov 20-Jul-11 21:41pm    
You're welcome.
Good luck, call again.
Espen Harlinn 20-Jul-11 9:30am    
Good reply, my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900