What is new in C# 2.0?


C# version 2.0 introduces some new cool features. I am listing these features based on coolness:

1. Partial Classes

Partial classes is one of the coolest feature added to C# language. Having partial classes in the language provides programmers to write cleaner interfaces. A partial class means "A single class can be defined in multiple physical files.". For example, I can have a ClassA, which is defined in three different AFile.cs, BFile.cs, and CFile.cs physical files.  

Now you may ask why would I want that? Do you remember ASP.NET or Windows Forms applications, where designer (Visual Studio IDE) generated code was written in a region and your code will be added after that. When writing larger user interface driven applications (for example Windows UI or Web UI), you may want to have user interfaces related code in a file, some logic in a separate file and so on. Now using partial classes, we can have designer generated code in a separate file, control event handlers in a separate file, and rest of the code in a separate file.

See more details here on Partial Classes.

2. Static Classes

C# 2.0 now supports static classes. A static class -

  • can not be instantiated. That means you can not create an instance of a static class using new operator.
  • is a sealed class. That means you can not inherit any class from a static class.
  • can have static members only. Having non static member will generate a compiler error.

See more details here on Static Classes.

3. Property Accessor Accessibility Modifiers

C# 2.0 supports access modifiers for property accessor, which means now you can allow access levels of get and set accessors of a property. For example, now I can write a property which can only be set from a derived class only  but not from other classes.  Read more details here.

4. Generics

Read more details on Generics here.

5. Anonymous Methods

Read more on Anonymouse methods here.

6. Nullable Types

C# 2.0 allows you to assign null values to primitive types including boolean and integer, which wasn't possible in previous version of C#. Read more details here.

 


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.