unity游戏开发-C#语言基础篇(匿名方法)

 class Program
    {
        public delegate void mydelegate();
        public event mydelegate muevent;
        static void Main(string[] args)
        {
      //匿名方法
            //两个参数
            //委托声明方式
            Func<int, int, int> f = (int a, int b) =>
            {
                return a + b;
            };

            //一个参数;
            Func<int, int> ff = (int a) =>
            {
                return a;
            };


            //第一种
            mydelegate my = new mydelegate(Test1);

            //第二种
            mydelegate my1 = Test1;

            //第三种
            Action ac = Test1;//没返回值;
            Func<int> func= Test2;//括号是返回值类型

            //第四种 委托事件  匿名方法一
            Func<int> fun = delegate()
            {

                return -1;
            };

            //第五种 事件委托 匿名方法二

            Action ac1 = () =>
            {
                Console.WriteLine("test");
            };


            Func<int, int> fun1 = (int b) =>
            {

                return b;
            };

        }


        /// <summary>
        /// 主函数静态,方法必须是静态的;
        /// </summary>
        public static void Test1() {
            Console.WriteLine("test");
        }

        public static int Test2() {

            return -1;
        }
      
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容