Local Variable Type Inference and Anonymous Types
Anonymous types let's you to create classes or structure with actually defining the class or structure first. So what you would do in Orcas to define a new car:
var myNewCar = new { Model= "Civic", Manufacturer = "Honda", Year = 2006};
instead of declaring the class first and providing value for all the fields:
public class Car
{
public string Model;
public string Manufacturer;
public int Year;
}
Car c = new Car();
c.Model="Civic";
c.Manufacturer="Honda";
c.Year = 2006;
The var keyword in the first statement is called Implicitly Typed Local Variable. With this keyword you let the compiler guess what the type of the variable should be.
Extension Methods
Extension Methods will let you to extend existing classes with the following syntax:
public static class myExtension
{
public static void VeryNewMethod(this string s)
{
Console.WriteLine("VeryNewMethod says " + s);
}
}
So if you check the parameters of the VeryNewMethod you will notice that parameters are looking a bit weird. The parameter definition this string s tells the compiler that you wish to extend the string class with this method. From now on you can call VeryNewMethod on any strings:
string s = "Hello World!";
s.VeryNewMethod();
Object and Collection Initializers
With the Object and Collection Initializers you will be able to instantiate objects and collections much easier:
public class Car
{
public string Model;
public string Manufacturer;
public int Year;
}
Car myNewCar = new { Model= "Civic", Manufacturer = "Honda", Year = 2006};
or a collection
List<Car> myGarage = new List<Car>
{
new Car{ Model= "Civic", Manufacturer = "Honda", Year = 2006},
new Car{ Model= "Enzo", Manufacturer = "Ferrari", Year = 1999}
};
Query Expressions
Now with query expressions you can do the following type selections:
var cars = new List<Car>{
new Car{Manufacturer="Ferrari", Model ="Enzo", Year=200},
new Car{Manufacturer="Honda", Model="Civic", Year=2005}
};
var newCars = from x in cars
where x.Year >= 1990
select new { CarName = x.Manufacturer + x.Model, Year = x.Year };
Lambdas Bound to Delegates and Expression Trees
Car myDreamCar = cars.Find(c => c.Manufacturer == "Ferrari");
Lambda expressions are responsible that you can do the filtering for the cars without writing a new method.