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; }
        }
    }
  • 相关阅读:
    ue4 Windows RawInput Plugin
    UE4 VR中一种比较清晰的UI制作方式
    C# 自定义特性及反射
    C# 委托
    java+orace+hql分页
    数据库小知识总结
    往oracle数据库表中插入五十万条数据
    jsp页面传到action乱码问题
    常见数据库对象与java.sql.Types对照
    Oracle数据库初探
  • 原文地址:https://www.cnblogs.com/macT/p/10213021.html
Copyright © 2011-2022 走看看