There are several .NET language enhancements to be introduced with Visual Studio 2008 including implicitly typed variables, extension methods, anonymous types, object initializers, collection initializers and automatic properties. These language enhancements, along with features like generics, are critical to the use of some of the new features, such as LINQ with the ADO.NET Entity Framework. What can be confusing is that these features are often referred to in the same conversation as LINQ. Because of this relation by association, you may be led to believe that these features are part of LINQ. They are not; they are part of the .NET Framework 3.5 and the VB 9 and C# 3.0 languages. They are very valuable in their own rights as well as playing a huge role for LINQ. Key language features including · Automatic Property setters/getters· Object Initializers· Collection Initializers· Extension Methods· Implicitly Typed Variable· Anonymous Types Automatic Property setters/getters:public class Customer { public int CustomerID { get; set; } public string CompanyName { get; set; } public Address BusinessAddress { get; set; } public string Phone { get; set; } } Object Initializers:Customer customer = new Customer { CustomerID = 101, CompanyName = "Foo Company", BusinessAddress = new Address { City="Somewhere", State="FL" }, Phone = "555-555-1212" }; Collection Initializers:List<Customer> custList = new List<Customer> { new Customer {ID = 101, CompanyName = "Foo Company"}, new Customer {ID = 102, CompanyName = "Goo Company"}, new Customer {ID = 103, CompanyName = "Hoo Company"} }; Extension Methods:public static class MyExtensions { public static int Cube(this int someNumber) { return someNumber ^ 3; } }int oneSide = 3; int theCube = oneSide.Cube(); // Returns 27 Anonymous Types And Implicitly Typed Variable:var dog = new { Breed = "Cocker Spaniel", Coat = "black", FerocityLevel = 1 };
Regards,
Naveed Akhtar
Microsoft Certified Professional Developer
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Please remember to click “Mark as Answer”, if it is solution to your Problem