class Program
{
static void Main(string[] args)
{
Person person = new Person();
person.Name = "王一博";
person.Hello();
string s = "等风来,也等你!";
Console.WriteLine(s.AddString());
Console.ReadLine();
}
}
public class Person
{
public string Name { get; set; } = "蓝忘机";
}
public static class PersonExt
{
/* 扩展类和实用类必须在同一个命名空间 */
//使用 this 表示为 Person类的扩展方法
public static void Hello(this Person person)
{
Console.WriteLine($"你好啊:{person.Name}");
}
public static string AddString(this string str)
{
return str + "不过,那是面对对的人说的。";
}
}