C# 4.0 goes dynamic

Anders Hejlsberg is explaining new features in C# 4.0, a future version, at Microsoft’s PDC. The big new feature, he says, is support for dynamic typing. Currently C# uses static typing, which means that when you call object members like methods and properties, the compiler checks that they exist or raises an error if they do not. By contrast, with dynamic typing you can call any old method or property, and they are not checked until runtime.

C# 4.0 will support dynamic typing through a new static type called “dynamic” (this raised a laugh at PDC). In other words, if you declare a variable as dynamic:

dynamic obj;

then you can call what you like as if it were a member of obj, and it will be resolved at runtime.

Hejsberg showed in his demonstration how this simplifies interop with other dynamic languages like JavaScript or Python.

Other new features are named parameters and optional parameters. This is a big win for COM interop – automating Microsoft Office, for example, from C# has always been painful because COM was designed to support optional parameters. C# got round this with an ugly hack “ref.missing”. All gone in C# 4.0.

Technorati tags: , ,
VN:F [1.9.18_1163]
Rate this post
Rating: 0.0/10 (0 votes cast)

Related posts:

  1. Dynamic language slowdown at Microsoft?
  2. Measure the dynamic range of your CDs and downloads
  3. Hyper-V disk I/O: performance of dynamic vs fixed virtual hard disks
  4. Speeding page load with dynamic JavaScript
  5. The frustration of developing for Facebook with C#

3 comments to C# 4.0 goes dynamic