using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 扩展方法
{
class Program
{
static void Main(string[] args)
{
string s = "sdfsdfsdfsd";
string s1= s.QuotedStr().QuotedStr();
Console.WriteLine(QuotedStr(s));
Console.WriteLine(s1);
Console.ReadLine();
}
static string QuotedStr(string s)
{
return "/""+s+"/"";
}
}
static class StringExt //注意扩展方法要声明道static中
{
//方法是static 在参数前要加上this
public static string QuotedStr(this string s)
{
return "/"" + s + "/"";
}
}
}
扩展方法
使用扩展方法简化字符串操作
最新推荐文章于 2023-03-23 23:09:28 发布
1045

被折叠的 条评论
为什么被折叠?



