| 1 2 3 4 5 6 7 8 9 10 |
namespace MyExtensionMethods
{
public static class MyExtensions
{
public static int MyGetLength(this System.String target)
{
return target.Length;
}
}
}
|
使用时,需要引入这个名字空间,引用如下:
?| 1 2 |
string str = "dafasdf";
int len = str.MyGetLength();
|
以上这篇C# 为String类型增加方法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。