Anonymous types with Example code in C#.Net (C# 3.0 feature)

This is new feature in C# 3.0. These are data types and will use at runtime. This datatypes will generate at compile class not like normal class.

For doing this opeartions we will use var keyword. Visual studio is providing Intellisense support for the Anonymous class.

All the properties data types of the class are compiler generated only.

Below example shows, how to create and use of Anonymous classes.

Example:

    class Program
    {
        static void Main(string[] args)
        {
            var emp= new {eid="1",ename="Ranga Rajesh Kumar"};

            Console.WriteLine(emp.ename); //output: Ranga Rajesh Kumar
        }
    }


If you have any queries or suggestions, please feel free to ask in comments section.
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar