JavaScript进阶之路漫漫其修远兮。(~强烈建议使用Sublime编辑器查看本站给出的示例代码,因为它帅呆了~)
  • 首页
  • 其他
  • C# 接口、Dictionary、Action、Func简单实用

作者:田大才子2017-2-9 14:41分类: 其他

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("嘻嘻嘻嘻嘻");
        }
    }
}


温馨提示如有转载或引用以上内容之必要,敬请将本文链接作为出处标注,谢谢合作!

已有 0/5134 人参与

发表评论:

个人公众号,希望您的关注~