zoukankan      html  css  js  c++  java
  • 为匿名类型添加方法

    1:这个做法不太常用

    2:这个方法要传递两个参数,

    打算用扩展方法解决这个问题,

    但是扩展方法又不能用在匿名类型上,

    有点郁闷

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication8
    {
        class Program
        {
            static void Main(string[] args)
            {
                Func<string, string, string> getAllName = delegate(string first,string last)
                {
                    return string.Format("{0} {1}", first, last);
                };
    
                var myObj = new { firstName = "allen", secondName = "Liu", getName = getAllName };
                //这里需要传递两个参数,有点郁闷
                string myName = myObj.getName(myObj.firstName,myObj.secondName);
                Console.WriteLine(myName);
                Console.ReadKey();
            }
        }
    }
    
    
  • 相关阅读:
    Linux 常用命令
    去除重叠区间
    Python 小工具之大文件去重
    有趣的pyfiglet
    杨辉三角
    Paginator分页
    Linux用户和用户组
    Grub介绍
    Linux系统运行级别
    Linux系统启动流程
  • 原文地址:https://www.cnblogs.com/liulun/p/1689501.html
Copyright © 2011-2022 走看看