It's now possible to create class definitions on the fly. This is the concept of anonymous types, where the type is based on the signature of the class. To create an anonymous type, use the following:
new { First = "B", Second="C" };
With this new type, we now have a new class with a First property of type string, and a Second property of type string. However, nothing happens with the class because we have to store it somewhere. This is where the "var" keyword comes into play:
var stringValue = "X";
var instance = new { First = "B", Second = stringValue };
Instance now represents our anonymous type. The compiler will parse the above syntax and create a standard CLR type which has 2 properties First and Second and assign these properties type based on the inilization values. Here both the property will have type string as they have been inilized as string.
In Visual Studio 2008, there is full intellisense support for this. When creating an anonymous type, make sure a value is supplied to the property, or that it can infer the type from a variable; otherwise, if a null is supplied, a compile error occurs.
Revision number 2, Friday, July 04, 2008 10:42:27 AM by vik20000in
You must Login to comment.
Revision #12
Mon, Feb 16, 2009 4:03 PM
by
|
Visual Studio 2008
Visual Studio 2008is theversion of Visual Studio which comes with the .NET Framework 3.5. It was released to MSDN subscribers on 19 November 2007 alongside the.NET Framework 3.5. Visual Studio 2008 can target developmentin .NET Framework versions 2.0, 3.0
|
Revision #4
Mon, Feb 4, 2008 8:00 AM
by
|
Deployment
Deployment continues to get easier, but there's still a few gotchas here and there. Check out these choice articles for you deployment questions. Web Deployment Projects- Fritz Onion's most excellent article on Web Deployment Projects. He goes into
|
New
Mon, Feb 4, 2008 8:00 AM
by
|
LINQDataSource
There's quite a few data source controls in ASP.NET and one that folks are increasingly excited about is the LINQDataSource. Blogs LINQ to SQL (Part 5 - Binding UI using the ASP:LinqDataSource Control) - This is the best place to start to get your head around
|
Revision #4
Thu, Dec 25, 2008 9:04 PM
by
|
HTML
Visual Studio 2008 adds dramatically improved HTML and CSS Designer Support. From ScottGu: "VS 2008 now uses the same web designer that ships with Microsoft's new Expression Web product. In addition to providing lots of new functionality, you'll
|