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: Coding Practices


17. Always use a curly brace scope in an if statement, even if it contains a single statement.

18. Avoid function calls in Boolean conditional statements. Assign into local variables and check on them.

bool IsEverythingOK()
{…}
 
// Avoid
if(IsEverythingOK())
{…}
// Correct
bool ok= IsEverythingOK();
if (ok)
{…}

19. Always use zero based arrays.

20. Always explicitly initialize an array of reference types using a for loop.

public class MyClass
{ }
const int ArraySize = 100;
MyClass[] array = new MyClass[ArraySize];
for (int index =0; index< Array.Length; indexer++)
 {
  Array[index]=new MyClass();
 }

21. Do not provide public or protected member variables. Use properties instead.

22. Avoid using “new” inheritance qualifier. Use “override” instead.

23. Always check a delegate for null before invoking it.

24. Prefer using explicit interface implementation.

25. Never hardcode strings that might change based on deployment such as connection strings.

26. Use String. Empty instead of “”.

//Avoid
string name=”";
//Correct
string name=string.Empty;

27. When building a long string use “StringBuilder”, not “String”.

28. Don’t use late binding invocation when early-binding is possible.

29. Use application logging and tracing.

30. Never use “go to” unless in a switch statement fall-through.

31. Always have a default case in a switch statement that asserts.

32. Don’t use the “this” reference unless invoking another constructor from within a constructor.

33. Do not use the base word to access base class members unless you wish to resolve a conflict with a subclasses member of the same name or when invoking a base class constructor.

Pages: 1 2

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

No comments yet.

Leave a comment

(required)

(required)

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