C# Func<> 委托

没有参数: Func<TResult>

有参数:Func<T,TResult>

T代表传入参数类型,TResult代表返回参数类型,当然可以有多个参数T1、T2、T3…

上代码

 class FuncTest
    {
        string One(int num, string str, float f)
        {
            return $"{num},{str},{f}";
        }

        bool Tow()
        {
            return false;
        }


        public void Test(int a, Func<int, string, float, string> func, Func<bool> func2)
        {
            Console.WriteLine($"{a}: {func(1,"123",3.25f)}");
            if (func2())
            {
                Console.WriteLine("T");
            }
            else {
                Console.WriteLine("F");
            }
        }


        public void Test() {
            Test(1, One, Tow);
        }

    }

posted @ 2021-08-16 18:58  宋桓公  阅读(20)  评论(0编辑  收藏  举报