zoukankan      html  css  js  c++  java
  • Func<T1, TResult> 委托

    1.Func<T1, TResult> 用法以及含义
       封装一个具有T参数并返回 TResult 参数指定的类型值的方法。如果不需要使用返回TResult 请使用Action<T>
    2.如果要使用需要引用System.Core
    3.语法格式为:
       public delegate TResult Func<T1, TResult>(
        T1 arg1,
         )

    类型参数说明

    T1
    此委托封装的方法的第一个参数类型。
    TResult

    此委托封装的方法的返回值类型。

    using System;
    
    delegate string[] ExtractMethod(string stringToManipulate, int maximum);
    
    public class DelegateExample
    {
       public static void Main()
       {
          // Instantiate delegate to reference ExtractWords method
          ExtractMethod extractMeth = ExtractWords;
          string title = "The Scarlet Letter";
          // Use delegate instance to call ExtractWords method and display result
          foreach (string word in extractMeth(title, 5))
             Console.WriteLine(word);
       }
    
       private static string[] ExtractWords(string phrase, int limit)
       {
          char[] delimiters = new char[] {' '};
          if (limit > 0)
             return phrase.Split(delimiters, limit);
          else
             return phrase.Split(delimiters);
       }
    }
    
  • 相关阅读:
    随机数
    ASP .NET下的301重定向如何做
    网站外部链接建设方案
    解析ASP.NET WebForm和Mvc开发的区别
    委托、匿名委托和lambda表达式
    图片垂直居中
    jquery函数写法
    [转]函数方法常用的动词
    CSS Hack
    富文本编辑器
  • 原文地址:https://www.cnblogs.com/zjw2004112/p/1576807.html
Copyright © 2011-2022 走看看