tags:

views:

4637

answers:

8

What are the coolest new features that you guys are looking for, or that you've heard are releasing in c# 4.0.

+1  A: 

the dynamic keyword looks like it can bridge the gap between dynamic languages like IronRuby or IronPython quite nicely, which will probably help its adoption in the Microsoft monoculture... that excites me.

While I'm intrigued by it, I'm also worried that it will be overused, like Generics and LINQ, SQLCLR, etc :)

Ben Scheirman
i'm also worried about the overuse of dynamic. Hopefully I can add style check it on checkin
CVertex
Generics overused? I agree about LINQ being sometimes overused though...
Meta-Knight
+19  A: 

The dynamic stuff sounds cool if you need it but I don't expect to use it very often.

The generic variance for delegates and interfaces is similar - the lack of variance is a headache at the moment, but many of the places where it's a pain won't be covered by the limited variance available in C# 4.

The COM features don't particularly interest me - I really ought to get more of a handle on what they are though.

Optional and named parameters could make a big difference when building immutable types: it enables syntax like:

Person p = new Person (name: "Jon", age: 32);

without having mammoth combinations of constructor overloads. I'd prefer a bit more support for writing immutable types in the form of readonly automatically implemented properties, but I don't expect we'll get those. (They certainly aren't in the proposed feature list at the moment.)

I'm personally actually more interested in a couple of the framework features of .NET 4.0 - in particular code contracts and parallel extensions.

Jon Skeet
To add an example of this, see: http://marcgravell.blogspot.com/2008/11/immutability-and-optional-parameters.html
Marc Gravell
This video is informative if you have an hour to kill...http://channel9.msdn.com/pdc2008/TL16/
Code Contracts + 1
Stephen Newman
Named parameters also make boolean arguments much, much clearer. Would you like to see 'True' or 'UseWidget: True'?
Strilanc
I think the idiomatic example of needing "the dynamic stuff" is COM interop, even though it breaks my preferred method of API discovery with IntelliSense.
Jurily
@Jurily: Not everything about dynamic interop needs to break IntelliSense. You can use implicit conversions from dynamic but specify the target type, and then still have IntelliSense on the result. It's a compromise solution, basically.
Jon Skeet
+10  A: 

Method parameter default values:

public void MyMethod1(string value1 = "test", int num1 = 10, double num2 = 12.2)
{
  //...
}

Also maybe anonymous return types:

public var MyMethod2()
{
  // ..
}
CMS
So does parameter default values mean we can call them like this? obj.MyMethod1("test",1); Would work with your provided method?
mxmissile
This was the #1 thing I missed when switching from VB.NET to C#.
MiffTheFox
would work and the variables will look like: value1="test", num1=1, num2=12.2
Atmocreations
Just make sure you understand [how they work](http://stackoverflow.com/questions/241134/what-is-the-worst-gotcha-in-c-or-net/2837357#2837357)
BlueRaja - Danny Pflughoeft
+5  A: 

IDynamicObject, the glue behind dynamic, allows interpretation of a call at runtime.

This is interesting for inherently untyped scenarios such as REST, XML, COM, DataSet, dynamic languages, and many others. It is an implementation of dynamic dispatch built on top of the Dynamic Language Runtime (DLR).

Instead of cumbersome reflection semantics, you dot into variables declared as dynamic. Imagine working with Javascript objects from Silverlight:

dynamic obj = GetScriptObject();

HtmlPage.Window.Alert(obj.someProperty);

All C# syntax is supported (I believe):

HtmlPage.Window.Alert(obj.someMethod() + obj.items[0]);

Reflection itself looks a lot cleaner:

public void WriteSomePropertyValue(object target)
{
    Console.WriteLine((target as dynamic).SomeProperty);
}

public void WriteSomeMethodValue(object target, int arg1, string arg2)
{
    Console.WriteLine((target as dynamic).SomeMethod(arg1, arg2));
}

dynamic is another tool in the toolkit. It does not change the static vs. dynamic debate, it simply eases the friction.

Bryan Watts
Holy crap.... Hadn't thought about casting objects to dynamic. That DOES make reflection a crap-ton easier!
Will
+2  A: 

Enhanced support for Expression Trees!

Chris Shouts
+4  A: 

Tuples

James L
+2  A: 

Not strictly C#, but since .NET is tagged here's a good link regarding BCL changes.

Note to self: Must rename my Stopwatch.Restart() extension method before 4.0 is released :)

Si