• 大小: 1.62KB
    文件类型: .cs
    金币: 1
    下载: 0 次
    发布日期: 2020-12-26
  • 语言: C#
  • 标签: C#  delegate  

资源简介

C# delegate、Func、Action 使用示例

资源截图

代码片段和文件信息

class Program
    {
        private delegate int GetSum(List list); // First Definition Delegate
        static void Main(string[] args)
        {
            //C# delegate

            List list = new List()
            {
                    new Product{ProductName=“Iphone4s“ Price=3000}
                new Product{ProductName=“Iphone5“Price=4000}
                new Product{ProductName=“Ipad4“Price=3500}
            };
            GetSum s = GetTotal;
            Console.WriteLine(s(list));

            //C# Func

            //Method A
            Func int> func = GetTotal;
            Console.WriteLine(func(list));

            //Method B
            Func int> func1 = delegate(List listA)
   

评论

共有 条评论