C# extention extension

class

   1: public static class 任意类名1
   2: { 
   3:     public static string 任意方法名1(this <T>  plugins,....)
   4:     {
   5:         return "只要命名空间有引用,<T>  的类型能匹配到,这个扩展就可用,真方便";
   6:     }
   7: }

比如

   1: 1: public static class AnyName
   2: 2: { 
   3: 3:     public static string GetMyName1(this string thisval)
   4: 4:     {
   5: 5:         return "只要命名空间有引用,<T>  的类型能匹配到,这个扩展就可用,真方便";
   6: 6:     }
   7: 7: }
   8: 8:  
   9: 9: string sss = "";
  10: 0: string sss1 = sss.GetMyName1();

再如

   1: 1: public static class AnyName123
   2: 2: { 
   3: 3:     public static string  Getval(this int thisval)
   4: 4:     {
   5: 5:         return thisval.Tostring();
   6: 6:     }
   7: 7: }
   8: 8:  
   9: 9: int sss = 0;
  10: 0: string  sss1 = sss.Getval();
posted @ 2012-05-21 15:45  LuckJason  阅读(271)  评论(0编辑  收藏  举报