zoukankan      html  css  js  c++  java
  • 委托、Action、Func使用

    参考

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
        class Program
        {
           // private delegate void BuyBook();
            static void Main(string[] args)
            {
    
                //BuyBook buybook = new BuyBook(Book);
                //buybook();
                //Action<string> BookAction = new Action<string>(Book);
                //BookAction("百年孤独");
                //Func<string> RetBook = new Func<string>(FuncBook);
                //Console.WriteLine(RetBook());
                //Func<string, string> RetBook = new Func<string, string>(FuncBook);
                //Console.WriteLine(RetBook("aaa"));
                Func<string> funcValue = delegate
                {
                    return "我是即将传递的值3";
                };
                Func<List<Student>> funcValue2 = delegate
                {
                    List<Student> list = new List<Student>()
                {
                    new Student(){SName="张同学",SAge=11,Ssex="男"},
                     new Student(){SName="李同学",SAge=12,Ssex="男"},
                     new Student(){SName="王同学",SAge=13,Ssex="男"},
                     new Student(){SName="赵同学",SAge=14,Ssex="男"},
                };
                    return list;
                };
                DisPlayValue(funcValue);
                DisPlayValue2(funcValue2);
                Console.ReadKey();
            }
            private static void DisPlayValue(Func<string> func)
            {
                string RetFunc = func();
                Console.WriteLine("我在测试一下传过来值:{0}", RetFunc);
            }
            private static void DisPlayValue2(Func<List<Student>> func)
            {
                List<Student> list = new List<Student>();
                list = func();
              
            }
            public static void Book(string BookName)
            {
                Console.WriteLine("我是买书的是:{0}", BookName);
            }
            public static string FuncBook()
            {
                return "送书来了";
            }
            public static string FuncBook(string BookName)
            {
                return BookName;
            }
        }
        public class Student
        {
    
            public string SName { get; set; }
    
            public int SAge { get; set; }
    
            public string Ssex { get; set; }
        }
    }
  • 相关阅读:
    Datatables 在asp.net mvc
    VS Code开发调试.NET Core
    领域模型中的用户设计
    MVC数组模型绑定
    Java RMI(远程方法调用) 实例与分析 (转)
    oracle转mysql总结(转)
    Windows远程桌面连接Ubuntu 14.04 (转)
    oracle转Mysql中,varchar2(10)和number应该转换为什么类型? (转)
    MySQL与Oracle的语法区别详细对比 (转)
    python购物淫秽数据分析(2)
  • 原文地址:https://www.cnblogs.com/macT/p/10213021.html
Copyright © 2011-2022 走看看