码迷,mamicode.com
首页 > Windows程序 > 详细

C# 语法 ( 扩展方法 )

时间:2017-01-20 15:55:51      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:声明   turn   命名空间   bcd   stc   char   方法   stat   --   

<!-- 扩展方法的声明 --> 注 : 尽量少用

  1, 声明一个公共静态的类  public static class 类名 {}

  2,在类中声明一个公共静态的方法 ,参数用关键字 this 修饰  如 : 

   public static string FirstCharToUp(this string s) { return s }

  3,调用方法时, 引入命名空间,用String对象直接点出, 如 :

   String s  = "abcdeg";

   s = s.FirstCharToUp();

 

C# 语法 ( 扩展方法 )

标签:声明   turn   命名空间   bcd   stc   char   方法   stat   --   

原文地址:http://www.cnblogs.com/lovling/p/6322838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!