方法泛型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;

namespace ConsoleApplication1
{
    class Program
    {
        private static T1 Add<T1,T2>(T1 a,T2 b)
        {
            dynamic m = a;
            dynamic n = b;
            return (dynamic)(m + n);
        }
        static void Main(string[] args)
        {
            //string[] names = { "ganquanfu", "ligang", "zhongshi" };
            //var res = names.Where(name => (name.IndexOf("gan") > -1));
            //foreach (var item in res)
            //{
            //    Console.WriteLine(item);
            //}
            //dynamic name = new ExpandoObject();
            //name.Name = "ganquanfu";
            //name.Age = 23;

            Console.WriteLine(Add(10,20)) ;//输出30
            Console.WriteLine(Add("gan", "quanfu"));//输出ganquanfu

            Console.Read();
        }

 

    }

    class People
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
}


 

posted @ 2013-04-25 20:46  Predator  阅读(130)  评论(0编辑  收藏  举报