Create a lambda from a delegate in CSharp

Description

The following code shows how to create a lambda from a delegate.

Example


using System;//w w  w  .  j  ava 2 s.co  m
delegate int Transformer(int i);

class Test {
    static void Main() {
        Transformer square = x => x * x;
        Console.WriteLine(square(3));    // 9
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor