首页 > 编程 > C# > 正文

C# 为String类型增加方法详解

2019-10-29 21:24:14
字体:
来源:转载
供稿:网友
namespace MyExtensionMethods {   public static class MyExtensions   {     public static int MyGetLength(this System.String target)     {       return target.Length;     }   } } 

使用时,需要引入这个名字空间,引用如下:

string str = "dafasdf"; int len = str.MyGetLength(); 

以上这篇C# 为String类型增加方法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持VEVB武林网。

 


注:相关教程知识阅读请移步到c#教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表