C#函数的参数中含this
函数的参数中含this(扩展方法)
扩展方法必须在非泛型静态类中定义
如下代码
public static class Program
{
static void Main(string[] args)
{
var str = "Test for print string";
str.PrintString();
Console.ReadKey();
}
public static void PrintString(this string s)
{
Console.WriteLine(s);
}
}
结果如下:
Test for print string

浙公网安备 33010602011771号