lambdaの読み方

lambdaの読み方

C#などのプログラミング言語で利用される「lambda」の読み方を掲載してます。

読み⽅

ラムダ」と読みます。

lambdaとは

C#では、delegete宣言を省略することができます。

以下は、ラムダ式を利用したサンプルとなります。

namespace testapp
{

    class Program
    {
        static void Main(string[] args)
        {
            // 引数 なし 戻り値 なし
            Action action1 = () => { Console.WriteLine("hello World"); };
            action1();

            // 引数 あり 戻り値 なし
            Action<string> action2 = (msg) => { Console.WriteLine(msg); };
            action2("hello world");

            // 引数 複数 戻り値 なし
            Action<string, string, string> action3 = (msg1,msg2,msg3) => { Console.WriteLine(msg1 + msg2 + msg3); };
            action3("hello", "world","!!");

            // 引数 なし 戻り値 あり
            Func<int> func1 = () => { return 10; };
            Console.WriteLine(func1());

            // 引数 あり 戻り値 あり
            Func<int, int> func2 = (x) => x * 2; ;
            Console.WriteLine(func2(2));

            // 引数 複数 戻り値 あり
            Func<int, int, int> func3 = (x,y) => x * y;
            Console.WriteLine(func3(2,3));

        }

    }
}