Explanation of Func

前端 未结 4 1888
执笔经年
执笔经年 2020-12-07 09:02

I was wondering if someone could explain what Func is and how it is used with some clear examples.

4条回答
  •  佛祖请我去吃肉
    2020-12-07 09:08

    It is a delegate that takes one int as a parameter and returns a value of type string.

    Here is an example of its usage:

    using System;
    
    class Program
    {
        static void Main()
        {
            Func func = bar;
    
            // now I have a delegate which 
            // I can invoke or pass to other
            // methods.
            func(1);
        }
    
        static String bar(Int32 value)
        {
            return value.ToString();
        }
    }
    

提交回复
热议问题