This is a mirror of official site: http://jasper-net.blogspot.com/

3 simple and effective tips to improve your classes in C#

| Thursday, April 7, 2011
The other day I was taking a look to a C# Web application develop by a co-worker. The application was fine and it delivered the functionality proposed. Nevertheless, I found some common errors (or things to improve) in the way the classes were written. Let’s go ahead with some simple and useful tips to write C# classes.

Tip # 1: Define only one class per file.

C# allow us to define more than one class per file. This is a useful feature is you want just a few files in your source code. Personally, I don’t like to make use of this for a couple of reasons because if you take a quick look to the files in your code, you don’t know where are the classes because a file can contain more than one class.

Tip # 2: The class should have the same name as the file.

In a similar way, the name of the file could be different to the class name. For organization purposes, it’s better to define those names as the same. It makes your code more intuitive and easy to navigate through. This tip is part of the established naming conventions for C# defined by IDesign.

Tip # 3: Use C# coding standards for class names.

If you use conventions for class names, you can easily recognize that it’s a class and not a variable, an interface or something else.

Read more: Clouder

Posted via email from Jasper-net

0 comments: