zoukankan      html  css  js  c++  java
  • Linq 泛型查询

    赋值给System.Func<T,TResult> fun类型

    1,using System;

    delegate string ConvertMethod(string inString);

    public class DelegateExample
    {
       public static void Main()
       {
          // Instantiate delegate to reference UppercaseString method
          ConvertMethod convertMeth = UppercaseString;
          string name = "Dakota";
          // Use delegate instance to call UppercaseString method
          Console.WriteLine(convertMeth(name));
       }

       private static string UppercaseString(string inputString)
       {
          return inputString.ToUpper();
       }
    }

    2,

    using System;

    public class GenericFunc
    {
       public static void Main() { // Instantiate delegate to reference UppercaseString method
          Func<string, string> convertMethod = UppercaseString;
          string name = "Dakota";
          // Use delegate instance to call UppercaseString method
          Console.WriteLine(convertMethod(name));
       }

       private static string UppercaseString(string inputString)
       {
          return inputString.ToUpper();
       }
    }

    3,

    using System;

    public class Anonymous
    {
       public static void Main()
       {
          Func<string, string> convert = delegate(string s)  //匿名方法,直接在方法中返回值。
             { return s.ToUpper();};

          string name = "Dakota";
          Console.WriteLine(convert(name));  
       }
    }

     public static void Main()
       {
          Func<string, string> convert = s => s.ToUpper();  //赋值给拉吗达表达式
          string name = "Dakota";
          Console.WriteLine(convert(name));  
       }

  • 相关阅读:
    bzoj3653: 谈笑风生
    bzoj1858: [Scoi2010]序列操作
    bzoj1857: [Scoi2010]传送带
    bzoj1856: [Scoi2010]字符串
    bzoj1855: [Scoi2010]股票交易
    bzoj1854: [Scoi2010]游戏
    bzoj1853: [Scoi2010]幸运数字
    斜堆,非旋转treap,替罪羊树
    NOI2003 文本编辑器
    A_star poj2449 k短路
  • 原文地址:https://www.cnblogs.com/netact/p/1802177.html
Copyright © 2011-2022 走看看