??和dynamic

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)) ;
            //Console.WriteLine(Add("gan", "quanfu"));

 


            //Manager man1 = null;
            //Manager man2 = new Manager(2);
            //People people = new People();
            //Animal p = man1 ?? man2;  //输出Manager2,注意??必须是相同类型或能够隐形转换的
            //p.Show();

 

            Manager man1 = new Manager(1); ;
            Manager man2 = new Manager(2);
            People people = new People();
            Animal p = man1 ?? man2;  //输出Manager1,注意??必须是相同类型或能够隐形转换的
            p.Show();
            Console.Read();
        }

 

    }


    abstract class Animal
    {
        public abstract void Show();
    }

    class Manager:Animal
    {
        public int ID { get; set; }
        public Manager(int id)
        {
            this.ID = id;
        }
        public override void Show()
        {
            Console.WriteLine("Manager"+ID);
        }
    }
    class People:Animal
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public override void Show()
        {
            Console.WriteLine("People");
        }
    }
}

 

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