本文共 654 字,大约阅读时间需要 2 分钟。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ConsoleApplication27 { class Program { static void Main( string [] args) { int str1 = 200; var flag = str1.IsEmail(); Console.WriteLine(flag); Console.ReadLine(); } } public static class ExtensionMethods { public static bool IsEmail( this int str) { return true ; } } } |
扩展方法使您能够向现有类型“添加”方法,而无需创建新的派生类型、重新编译或以其他方式修改原始类型。
参考链接:
本文转自daniel8294 51CTO博客,原文链接:http://blog.51cto.com/acadia627/1927885,如需转载请自行联系原作者