Anonymous Delegate and Anonymous Type in C#

Below is a simple example demonstrating the usage of the Anonymous Delegate which is assigned to the Fun class.

The example demonstrates the delegate which concatenates the FirstName and last name of anonymous type and displays it

Anonymous Delegate and Anonymous Type

Func<string, string, string> FullName =

delegate(string FirstName, string LastName)

{

return FirstName + " " + LastName;

};

var Name = new { FirstName = "Senthil", LastName = "Kumar", Name = FullName };

Console.WriteLine(Name.Name);

Console.ReadLine();

    2 Comments

  1. Jon Preece
    July 11, 2013
    Reply

    I hope nobody actually writes code like this 😛

  2. July 11, 2013
    Reply

    @Jon – yup . But its always good to know the different ways of doing things 🙂

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...