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

Anonymous types

With the new feature of the object initializer and the new var data type we can create anonymous data types easily in C# 3.0.

For example, if we define a variable like this:

var a = new { Name = "name1", Address = "address1" };

at compile time, the compiler will actually create an anonymous type, as follows:

class __Anonymous1
{
    private string name;
    private string address;
    public string Name {
        get{
            return name;
        }
        set {
            name=value
        }
    }
    public string Address {
        get{
            return address;
        }
        set{
            address=value;
        }
    }
}

The name of the anonymous type is automatically generated by the compiler and cannot be referenced in the program text.

If two anonymous types have the same members with the same data types in their initializers, then these two variables ...

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