O'Reilly logo

WCF 4.0 Multi-tier Services Development with LINQ to Entities by Mike Liu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

New data type var

The first new feature that is very important for LINQ is the new data type, var. This is a new keyword that can be used to declare a variable and this variable can be initialized to any valid C# data.

In the C# 3.0 specification such variables are called implicitly-typed local variables.

A var variable must be initialized when it is declared. The compile-time type of the initializer expression must not be of null type but the runtime expression can be null. Once it is initialized its data type is fixed to the type of the initial data.

The following statements are valid uses of the var keyword:

            // valid var statements
            var x = "1";
            var n = 0;
            string s = "string";
            var s2 = s;
            s2 = null;
            string s3 = null;
            var s4 = s3;

At compile time, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required