教主的代言人
C# 接口、Dictionary、Action、Func简单实用
2017-2-9 田大才子

C# 接口、Dictionary、Action、Func简单实用


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InterfaceStudy
{
    class Program
    {
        static void Main(string[] args)
        {

            // 接口
            IKill kill;

            kill = new killLaobi();
            kill.killSomeoneBySomething();

            kill = new killJiba();
            kill.killSomeoneBySomething();

            // Dictionary
            Dictionary<string, object> d = new Dictionary<string, object>();
            d.Add("shabi", "233");
            d.Add("erbi", 123);
            Console.WriteLine(d["shabi"] + d["erbi"].ToString());

            // Action
            Action<string> ac = a =>
            {
                Console.WriteLine(a);
            };
            ac("tianqig");

            // Func
            Func<string, string> f = a =>
            {
                return a;
            };
            Console.WriteLine(f("sssss"));

            Console.Read();
        }
    }

    public interface IKill
    {
        void killSomeoneBySomething();
    }

    public class killLaobi : IKill
    {
        public void killSomeoneBySomething()
        {
            Console.WriteLine("哈哈哈哈哈");
        }
    }

    public class killJiba : IKill
    {
        public void killSomeoneBySomething()
        {
            Console.WriteLine("嘻嘻嘻嘻嘻");
        }
    }
}


发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容