repl.it
@kironroy/

lambda

C#

lambda, anonymous functions

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;


namespace LambdaExpressions
{
    class Program
    {
        static void Main(string[] args)
        {

            // lambda expressions (anonymous functions)

            // Func is a delegate
            Func<int, int> square = number => number * number;

            Console.WriteLine(square(5));


            const int factor = 6;

            Func<int, int> multipler = n => n * factor;

            var result = multipler(10);
            Console.WriteLine(result);

            Func<string, string> say = greeting => greeting;
            Console.WriteLine(say("Hello Jello"));



            
            // standard function
            //static int square(int number)
            //{
            //    return number * number;
            //}
        }
    }
}