C# 拓展方法实例

namespace BenJi
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("你要调试程序吗?yes/no");

string u = Console.ReadLine();
if (u == "yes")
{
string str = "1234567890";

Console.WriteLine(str.top6());  //输出  123456

}
Console.ReadLine();
}
}
public static class MyExtensions
{
public static string top6(this String str)
{
return str.Substring(0,6);

}
} 
}
原文地址:https://www.cnblogs.com/yangjinwang/p/4256087.html