C#的匿名函数


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace codeTest
{
    class Program
    {
        delegate int myDeletegate(int args0);

        delegate TResult myFunc<Targ0, TResult>(Targ0 arg0);

        static void Main(string[] args)
        {
            myDeletegate my = new myDeletegate(ShowNumber);
            //c# 2.0   Anonymous Method
            myDeletegate myA = delegate(int args0) { return args0; };
            //c# 3.0   expression
            myDeletegate myB = (x) => { return x; };

            myFunc<int, int> myC = (x) => { return x; }; 
            Console.WriteLine(my(10));
            Console.WriteLine(myA(10));
            Console.WriteLine(myB(10));
            Console.WriteLine(myC(10));
            Console.ReadLine();
        }

        static int ShowNumber(int args0)
        {
            return args0;
        }
    }






}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM