Func,Action

       // Func委託系列引用一個《有返回值的方法》,也就是將方法作爲另一個方法的“參數”

        static int CommonMethod(Func<int, int, int> operation, int[] nums, int a, int b)
        {
            int result = nums[a];
            for (int i = a + 1; i <= b; i++)
            {
                result = operation(result, nums[i]);
            }
            return result;
        }

      //Action委託接收一個沒有返回值的方法,在跨線程訪問可視化控件的時候經常使用。
      Action<string> act = (a) => Console.WriteLine("歡迎{0}", a);           

      act("你");

 

 

      List<Student> list = stuList.FindAll(s => s.StudentId > 10);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章