Friday, January 9, 2009

C# naming convention for constants

When I was working on C++, my naming convention for constants was to be ALL_CAPS. In C# the recommended naming convention for constants is Pascal casing (starts with upper case).

private const int MaxLimit = 100;

Even though it is a private field, it is not a variable and it cannot be accessed using "this" object within your class. Hence I prefer using Pascal casing to differentiate it with variable members, which are in Camel casing (starts with lower case) as per .NET naming convention.

Microsoft has come up with this cool tool named StyleCop that documents all the preferred conventions and it can also check your source code for compliance.

Check out this link for more information on StyleCop.
http://code.msdn.microsoft.com/sourceanalysis

2 comments:

  1. It is really a great work and the way in which u r sharing the knowledge is excellent.Thanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.Thanks for your informative article.
    Dot Net Training in chennai | dot net training institute in velachery

    ReplyDelete
  2. Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. dot net training and placement in chennai | dtop10 dot net training institutes in chennai

    ReplyDelete