private void button7_Click(object sender, EventArgs e) { ExtMethodDemo test = new ExtMethodDemo(); test.CallMethod(); Temp T = new Temp() { ID = 1, Name = "Test" }; var MyProduct = new { Name = "Vacuum Cleaner", Price = 94.99, Description = "Really sucks! Have your carpets clean in no time." }; MessageBox.Show(MyProduct.Description); int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var firstNumbersLessThan6 = numbers.TakeWhile(n => n < 6); int i = 0; MessageBox.Show((++i).ToString() + " " + (i++).ToString()); }
//https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/classes-and-structs/extension-methods static void Main(string[] args) { Console.WriteLine("System.Linq 中的扩展方法"); LinqOrderBy(); WriteLine("String ExtensionMethod WordCount"); string s = "Hello Extension Methods"; int i = s.WordCount(); WriteLine(i); WriteLine("ExtMethodDemo.ExtMethodDemoTest 扩展接口的额外参数传递以及 优先级(覆盖规则)"); ExtMethodDemo.ExtMethodDemoTest(); ReadKey(); }