Chapter 24. C# 4.0 Language Improvements

In Chapter 23, you learned about how C# evolved from a general-purpose, object-oriented programming (OOP) language to a multi-paradigm language. After its first release in 2002 (C# 1.0), the language matured amazingly. Version 2.0 added support for generic types and got great performance-boosting features such as iterators with the yield-construct, delegate inference, covariance and contravariance, and nullable types.

C# 3.0 gained a huge spin with the introduction of query expressions that allowed encapsulating LINQ technology into the language. This feature enabled the shift from the imperative data-processing model to the declarative one. In addition, many other "syntax noise-reduction" features were put into C# 3.0 to achieve the intended declarative strength.

The major theme for C# 4.0 is dynamic programming. Increasingly, objects are "dynamic" in the sense that their structure and behavior is not captured by a static type or, at least, not one that the compiler knows about when compiling your program. While C# remains a statically typed language, the Managed Languages Team targeted vastly improved interaction with the following:

  • Objects from other programming languages, such as Python or Ruby

  • Component Object Model (COM) objects accessed through the IDispatch interface

  • Objects with dynamically changing structure, such the ones in HTML Document Object Model (DOM)

  • Ordinary .NET types accessed through reflection

After reading this chapter, you ...

Get Visual Studio® 2010 and .NET 4, Six-in-one now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.