Anonymous Types In C#

In this post,we will learn about Anonymous Types In C# with an example.

Description:

In my previous posts I have explained various topics like Sealed Class in C#, Continue keyword in C#.Net, Difference between string and StringBuilder in C#, Difference between a struct and a class in C#, Boxing & Unboxing in C# ,Dynamic Type In C#, Named Arguments In C#, Basics Of Pointers In C#, Get site visitor count in asp.net, Convert generic list to datatable in Asp.Net C#.Net, Abstract Class in C# with Example.

Now in this post, I will explain about Anonymous Types In C# with appropriate example.

Anonymous types are use to create new type without defining them. It enable you to define read only properties into a single object without having to define type explicitly. Type is generated by the compiler and it is accessible only for the current block of code in the program.

You can create anonymous types by using “new” keyword with the object initializer. The Compiler creats a name for each anonymous type.

static void Main(string[] args)
        {
            var EmployeeData = new
            {
                FirtsName = "Adam",
                LastName = "Nivac"
            };
            Console.WriteLine("First Name : " + EmployeeData.FirtsName + "\nLast Name : " + EmployeeData.LastName);  

            Console.ReadLine();
        }

Summary

You can also read about ASP.NET, C#.NET, JQUERY, AJAX.

I hope you got an idea about Anonymous Types In C#.
I would like to have feedback for my blog.
Your valuable feedback, question, or comments about this article are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website