It's based around .NET 3.5. The numbering convention might seem a little strange; unlike 2.0 to 3.0 (which merely added new class libraries), 3.0 to 3.5 adds new language features. The .NET 3.0 features (eg WPF designer) that didn't work properly in VS 2005 EE do work in the new IDE too.
New C# 3 language features. Enjoy!
EDIT: Well, I knocked together a list of examples of the new features... I think they're cool. Evidently I'm alone in that!
Extension Methods
Classes and structures have a variety of exciting instance methods.
However, if a particular class is missing a method you really need, you'd have to create a new static method and call that method, passing the thing you want to act on as an argument - not very OOP!
Extension methods address this issue; just chuck your new methods into a static class using this as a special modifier on the first argument.
Code: Select all
/// <summary>Calculate the Rot13 encoded version of a string.</summary>
public static string Rot13(this string s) {
char[] Characters = s.ToCharArray();
for (int i = 0; i < Characters.Length; ++i) {
int c = Characters[i];
int d = char.ToLowerInvariant(Characters[i]);
if (d >= 'a' && d <= 'z') {
c += 13; d += 13;
if (d > 'z') c -= 26;
}
Characters[i] = (char)c;
}
return new string(Characters);
}
Code: Select all
string s = "Hello";
MessageBox.Show(s.Rot13());
One for the functional programming fans. These take anonymous methods a step further.
Code: Select all
Func<int, int, int> f = (x, y) => x * y;
MessageBox.Show(f(2, 3).ToString());
Code: Select all
var SourceData = new int[] { 8, 5, 6, 3, 2, 7, 4 };
var EvenNumbers = SourceData.Where(i => (i & 1) == 0);
If you've ever had to type in something like this:
Code: Select all
Dictionary<int, Dictionary<string, SomeLongCustomClassName>> X =
new Dictionary<int, Dictionary<string, SomeLongCustomClassName>>();
Object Initializers
If you've ever knocked up a class with lots of member properties, you might have seen something like this:
Code: Select all
var X = new SomeClass(10, 3, 2, "Hello", false, Fruits.Watermelon);
Code: Select all
Button B = new Button {
Text = "Hello",
Width = 100,
Height = 32,
DialogResult = DialogResult.OK
};
Similar syntax can be used to create anonymous types...
Code: Select all
var x = new { Name = "Ben", Country = "England" };
Implicitly Typed Arrays
Another one to save typing:
Code: Select all
var x = new[] { 1, 2, 3, 4, 5 };
I always felt that the whole idea of passing SQL as strings to databases was rather clunky, so why not build it into the language?
Using a query expression (rather than a lambda expression) to extract even numbers from an array could look like this:
Code: Select all
var SourceData = new[] { 8, 5, 6, 3, 2, 7, 4 };
var EvenNumbers = from i in SourceData where (i & 1) == 0 orderby i select i;