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);

}
} 
}

 

posted @ 2015-01-28 15:52  秋香姑娘请你不要紧张  阅读(191)  评论(0编辑  收藏  举报