New "var" keyword

 Rate It (0)

The var keyword is a new keyword that can infer its data type from the resulting set.  For instance, look at the following examples:

var one = 1; //infers an int

var two = "2"; // infers a string

var three = from c in Customers select c; //infers IQueryable<Customer>

var four = customers.FirstOrDefault(); //infers Customer reference

This means full intellisense is available in VS 2008, as long as the compiler can infer the type.  The following results in a compile error:

var five = null;

Becuase compiler couldn't  infer the type of the variable from null. “Var” is NOT a variant, everything is known by the compiler at compile-time.

 

Revision number 2, Thursday, October 02, 2008 8:56:36 PM by budugu

Comments

Related Articles

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

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

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

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. mbanavige (25)
  2. gilfink (14)
  3. MisterFantastic (10)
  4. anas (6)
  5. rohanisbond (4)
  6. PaulSpencer (3)
  7. random0xff (2)
  8. wejop (1)
  9. vik20000in (1)
  10. joycsharp (1)

Advertise Here

Microsoft Communities
Page view counter