Tanzim Saqib on .NET discovery

Innovate. Create. Share.

  Home  |   Contact  |   Syndication    |   Login
  43 Posts | 0 Stories | 19 Comments | 0 Trackbacks

News

Photo of Tanzim Saqib Tanzim Saqib is a Senior Developer, who spent half of his life on software and worked for many companies like #1 .NET controls provider Telerik Inc, #1 personalized Web 2.0 start-page like Pageflakes (acquired by LiveUniverse). He developed many projects ranging from banking solutions for Citibank, HSBC, Wamu, Wells Fargo etc. to Paperless Virtual University. He is industry's earliest and leading widget developer and as know as "Widget Master" to his peers.

He is a preacher of Microsoft technologies. While he jams with the latest additions to .NET, in his spare time he blogs at http://weblogs.asp.net/TanzimSaqib, maintains his personal website http://www.TanzimSaqib.com, leads .NET Research group. writes articles.

He is an easy going, fun loving, and passionate technology individual who is open to any kind of business opportunity and professional relationship. He currently lives in Bangladesh, but travels anywhere in the world on professional demand.

Email: me at TanzimSaqib dot com

Archives

Post Categories

Personal

Anonymous types are excellent addition to .NET “Orcas” release. These are a convenient language feature that allows developers to write code without bothering about what particular type of object they are dealing with. Anonymous types are declared by var keyword which you most of the times will see in different application of LINQ. It's true it great use with LINQ, but it's not a LINQ feature at all - it's a new language feature.

A very simple use of Anonymous types is (starting with a keyword var):

var helo = 123;

You can assign whatever type you like. But, unlike JavaScript once you assigned one type of value, you cannot assign to other types like this:

var helo = 123;
helo = "hello";

Again, unlike JavaScript, you cannot left a declaration unassigned. Do not ever mix up with JavaScript's var and .NET's one.

var helo;   // It won't compile

Take a look at variety of usage of Anonymous types. Enjoy the powerful Visual Studio's great intellisense:

var helo = 123;
Console.WriteLine(helo.Equals(123));

var hello = "hello";
Console.WriteLine(hello.Length);

var helloWorld = new List<string>() { "hello", "world" };
helloWorld.ForEach(delegate(string x) { Console.WriteLine(x); });

If we consider the performance issue, there's no extra footprint on CLR for Anonymous types. Before it goes to CLR's hands, vars are replaced with appropriate type so there's no extra effort for CLR to understand the types:

var hello = "hello";    // exactly same as: string hello = "hello";

Anonymous types are not only appropriate for lazy developers like me, but also have great effective usage in LINQ. I'll cover that one may be later sometime.

posted on Tuesday, December 04, 2007 9:08 PM