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("嘻嘻嘻嘻嘻"); } } }
发表评论: