函数的参数中含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
标签:Console,函数,C#,中含,static,Test,string
From: https://www.cnblogs.com/skc-6/p/17024531.html