Share via


Cool article on the new C# features

If you want a two page summary on what's new in the C# language in Whidbey, this article is for you:

https://msdn.microsoft.com/msdnmag/issues/04/05/C20/default.aspx

The three main ones discussed, among all the others:

- support for generics. Previously, if a collection contained value types, iterating over the elements would cause boxing and unboxing of those items. Now there are IEnumerable/IEnumerator interfaces that are type-safe and use generics to avoid this penalty.

- partial types. For the traditional C++ programmer, this is not new. You can now split the definition and implementation of a class or a struct across multiple files.

- and the coolest -- Anonymous delegates -- you dont need to create a class or a method just for the sake of using a delegate. You can now have anonymous methods and inline the code!

 

C# supports delegates for invoking one or multiple methods. Delegates provide operators and methods for adding and removing target methods, and are used extensively throughout the .NET Framework for events, callbacks, asynchronous calls, and multithreading. However, you are sometimes forced to create a class or a method just for the sake of using a delegate. In such cases, there is no need for multiple targets, and the code involved is often relatively short and simple. Anonymous methods is a new feature in C# 2.0 that lets you define an anonymous (that is, nameless) method called by a delegate.