s

C# Lambda expressions edit button Edit

author
Rakesh Kumar Sutar | calendar 25 January 2021 | 1656

Introduction

Lambda expressions are used to create an anonymous function. Lambda Expressions are two types

  • Expression lambda
  • Statement lambda

Syntax

  • Expression lambda
  • (input-parameters) => expression
  • Statement lambda
  • (input-parameters) => {  }

Example

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hello_World
{
    class Program
    {

        public delegate void nameing(string name);

       
        static public void Main()
        {
            Func square = x => x * x;
            Console.WriteLine("\n\n\t\t" square(7));
            Console.ReadLine();

        }
    }
}

    



Output