C#扩展方法

//扩展方法
//this指定什么类型,就要用什么类型的数据来调用
class Program
    {
        static void Main(string[] args)
        {

            int a = 10;
            Console.WriteLine(a.AA());

            ///////

            List<int> xx = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };

            xx.BB(p => p.Count > 0);


            Console.Read();
        }

        
    }
    static class aa
    {
        //简单
        public static int AA(this int a)
        {
            return a + 1;
        }

        //复杂
        public static int BB<T>(this List<T> x,Func<List<T>,bool> func)
        {
            return x.Count;
        }
    }
原文地址:https://www.cnblogs.com/xuxueming/p/11913703.html