zoukankan      html  css  js  c++  java
  • C# FUNC 应用

    复制代码
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace FuncDemo
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    //类似委托功能
                Func<stringint> test = TsetMothod;

                Console.WriteLine(test(
    "123"));

                Func
    <stringint> test1 = TsetMothod;


                
    //只需要调用这个类就可以减少重复的代码
                CallMethod<string>(test1,"123");

                
    //或者采用这种
                CallMethod<string>(new Func<stringint>(TsetMothod), "123");

                CallMethod(
    new Func<stringint>(TsetMothod), "123");


                
            }

           
            
    public static int TsetMothod(string name)
            {
                
    if (string.IsNullOrEmpty(name))
                {
                    
    return 1;
                }
                
    return 0;

            }

            
    //改造经常出现类似代码下面

            
    //try
            
    //{
            ////Do();只有这个方法改变
            //}
            
    //catch (System.Exception ex)
            
    //{
            
    //    //Log(e);
            
    //}
            
    //finally
            
    //{
            ////DoOther();
            //}

            
    //
            public static void CallMethod<T>(Func<T,int> func,T item)
            {
                
    try
                {
                   
    int i= func(item);
                   Console.WriteLine(i);
                }
                
    catch(Exception e)
                {

                }
                
    finally
                {

                }
            }


        }
    }

    FUNC示例 

  • 相关阅读:
    Bzoj 1010: [HNOI2008]玩具装箱toy(斜率优化)
    Cogs 376. [IOI2002]任务安排(后效性DP)
    Bzoj 1911: [Apio2010]特别行动队(斜率优化)
    Poj 2018 Best Cow Fences(分数规划+DP&&斜率优化)
    Bzoj 1212: [HNOI2004]L语言(AC自动机+DP)
    ZOJ 3228 Searching the String(AC自动机)
    Bzoj 3172: [Tjoi2013]单词(fail树)
    Hdu 3065 病毒侵袭持续中(AC自动机)
    Hdu 2896 病毒侵袭(AC自动机)
    Bzoj 2599: [IOI2011]Race(点分治)
  • 原文地址:https://www.cnblogs.com/mili3/p/2852718.html
Copyright © 2011-2022 走看看