RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Explore C# 4's New Dynamic Types and Named/Optional Parameters

Leverage these new features in C# 4.0 to interoperate with new dynamic .NET languages, and simplify your code.


# 4.0 includes a number of enhancements and additions, including:

  1. Support for dynamic lookup
  2. Support for both named and optional parameters
  3. Enhanced COM Interop features
  4. Support for variance

This article takes a look at the first two items in that list, provides examples, and shows how you can take advantage of them in your applications. A future article covers the last two items.

As you may be able to divine from the terms in the list, some of C#'s new features are tied into Microsoft's new Dynamic Language Runtime (DLR) environment—a new feature of the .NET Framework that enables dynamic languages to reside side-by-side and interoperate with statically typed languages.

Author's Note: To execute the code examples discussed in this article, you should have Visual Studio 2010 Beta 1 or later installed in your system.

Understanding the DLR

The DLR is built on top of the Common Language Runtime (CLR) and opens the door for a common set of technologies and tools to interoperate inside a common framework. Dynamically typed languages such as Python, Ruby, and JavaScript can reside alongside familiar statically typed .NET languages such as C#, Managed C++, and Visual Basic. The CLR provides a common platform where statically typed languages (e.g. C#, VB) can reside and interoperate, while the DLR sits on top of the CLR and provides a common platform for dynamically typed languages to reside and interoperate.

Figure 1. Components of the DLR: The DLR includes a .NET language integration layer, a set of runtime code components, and language binders.

The DLR adds a set of services that facilitate dynamic language implementations on .NET's managed platform. These services include support for a dynamic type system, a standard hosting model, and fast dynamic code generation. In addition, the DLR lets dynamic and static languages interoperate bi-directionally.

To support the DLR, the .NET Framework 4.0 contains a new System.Dynamic namespace. The Dynamic Language Runtime contains three layers (see Figure 1):

  1. The .NET Language Integration Layer
  2. The Dynamic Language Runtime Code Components
  3. Language Binders

The services the DLR provides include:

  • Dynamic Method Dispatch
  • Dynamic Code Generation
  • Hosting API

With that brief introduction to the DLR, you can move on to explore C#'s new features.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date