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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...