Tips n Tracks

  • Increase font size
  • Default font size
  • Decrease font size
  • default color
  • black color

Reference

Sample image

Microsoft .NET Framework Get Details.

Sample image

Microsoft .NET Framework Get Details.

Reference

Sample image Microsoft .NET Framework Get Details.
Sample image

Microsoft .NET Framework Get Details.


C# Coding Standards and Guidelines: Naming Conversions and Style


C# Coding Standards and Guidelines: Naming Conversions and Style

1) Use Pascal casing for type and method and constants.

public class SomeClass
{
const int DefaultSize= 100;
public SomeMethod ()
{}
}

2) Use camel casing for local variable names and method arguments.

public class SomeClass
{
int number;
void MyMethod (int someNumber)
{}

}

3) Prefix member variables with m_. Use Pascal casing for the rest of a member variable name following the m_.

public class SomeClass
{
private int m_Number;
}

4) Name methods using verb-object pair, such as ShowDialog ().

5) Method with return values should have a name describing the value returned, such as GetObjectState ().

6) Use descriptive variable names

  • Avoid single character variable names, such as i and t. Instead use index or temp.
  • Do not abbreviate words. (such as num instead of number)

7) All member variables should be declared at the top, with one line separating them from the properties or methods.

public class MyClass
{
int m_Number;
string m_Name;
public void SomeMethod1()
{ }
public void SomeMethod2()
{ }
}

8) Declare a local variable as close as possible to its first use.

9) Name interfaces with I prefix

interface IMyInterface
{..}

10) With the exception of zero or one, never hard-code a numeric value; always declare a constant instead.

11) Use the const directive only on natural constants such as the number of days of the week.

12) Avoid using const on read-only variables. For that, use the readonly directive.

public class MyClass
{
public const int DaysInWeek = 7;
public readonly int Number;

public MyClass(int someValue)
{
Number = someValue;
}
}

13) Always use C# predefined types rather than the aliases in the System Namespace.

object NOT Object.
string NOT String.
int NOT Int32.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

[...] C# Coding Standards and Guidelines: Naming Conversions and Stylehttp://www.tipsntracks.com/21/csharp-naming-conversions-and-style.html [...]

Pingback by Importance of Coding Standards for .NET Development | Tips n Tracks on August 10, 2008 @ 6:13 am

Leave a comment

(required)

(required)

*
To prove that you're not a bot, enter this code
Anti-Spam Image