• C# 委托Action和Func


    Action和Func是微软已经定义好的的两种委托类型,区别是Action是没有返回值的,而Func是需要返回值的。

     1             //Action内置委托的实例化及调用
     2             //不带参数
     3             Action myAction1 = () => { Console.WriteLine("这是一个Action委托的调用"); };
     4             myAction1();
     5             //带参数
     6             Action<string> myAction2 = (str) => {
     7                 Console.WriteLine("这是一个带参数的Action委托调用,参数:{0}", str);
     8             };
     9             myAction2("HelloWorld!");
    10             //多参数
    11             Action<string, string> myAction3 = (str1, str2) => {
    12                 Console.WriteLine("这是一个带参数的Action委托调用,参数1:{0},参数2:{1}", str1, str2);
    13             };
    14             myAction3("1", "2");
    15 
    16 
    17             //Func内置委托的实例化及调用
    18             //只有Func<T>类型,多参数Func<T,T,T>,最后一个T为返回类型
    19             Func<string> myFunc1 = () => "只有一个参数,就是返回类型";
    20             Console.WriteLine(myFunc1());
    21 
    22             Func<int, int, int> myFunc2 = (a, b) => { return a + b; };
    23             Console.WriteLine("多参数的返回类型情况,返回值:" + myFunc2(100, 400).ToString());
  • 相关阅读:
    新概念英语(第一册)Lesson 1
    第七篇、Python之模块/包
    解压序列
    eval函数
    python--magic module 文件类型识别
    MIME_type
    彻底删除git中的文件(包括历史提交记录)
    for循环与range()函数
    Linux 内核的 Makefile
    Python module ---- abc
  • 原文地址:https://www.cnblogs.com/mojiejushi/p/13190330.html
Copyright © 2020-2023  润新知