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.
Posted

 
Share this answer
 
Comments
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 http://en.wikipedia.org/wiki/FxCop[^]. 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), http://msdn.microsoft.com/en-us/library/aw58wzka.aspx[^]. For the pattern with "using" see http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.71%29.aspx[^], 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: http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx[^]. 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.

—SA
 
Share this answer
 
Comments
thatraja 20-Jul-11 3:07am    
Excellent, 5!
Sergey Alexandrovich Kryukov 20-Jul-11 3:10am    
Thank you, Raja.
--SA
unknowndentified10111 20-Jul-11 5:43am    
Superb.. Thanks..
Sergey Alexandrovich Kryukov 20-Jul-11 21:41pm    
You're welcome.
Good luck, call again.
--SA
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