c#Func依頼

4427 ワード

public delegate TResult Func<in T, out TResult>(T arg);

パラメータタイプ
T:この依頼メソッドのパラメータタイプ
TResult:この委任メソッドの戻り値タイプ
Arg:この委任パッケージメソッドのパラメータ
using System;

namespace  
{
    // 
    class Program
    {
        public static string UppercaseString(string name)
        {
            return name.ToUpper();
        }
        public static void Main()
        {
            Func<string, string> translation = UppercaseString;
            string name = "make";
            Console.WriteLine(translation(name));

        }
    }
}
using System;

namespace  
{
    // 
    class Program
    {
       // 
        public static void Main()
        {
            Func<string, string> translation = delegate (string s) { return s.ToUpper(); };
            string name = "make";
            Console.WriteLine(translation(name));

        }
    }
}
using System;

namespace  
{
    // 
    class Program
    {
       // lambda 
        public static void Main()
        {
            Func<string, string> translation = x => x.ToUpper();
            string name = "make";
            Console.WriteLine(translation(name));
        }
    }
}