110,571
社区成员
发帖
与我相关
我的任务
分享
public class Program
{
private static void Main(string[] args)
{
Person xiaoHong = new Person();
xiaoHong.GetType().GetProperty("Name").SetValue(xiaoHong, "小红");
xiaoHong.GetType().GetProperty("Age").SetValue(xiaoHong, 10);
xiaoHong.GetType().GetMethod("SaySomeThing").Invoke(xiaoHong, new object[] { "Hello World!" });
Person xiaoMing = new Person() { Age = 20, Name = "小明" };
xiaoMing.SaySomeThing("Nice to meet you!");
Console.ReadKey();
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public void SaySomeThing(string words)
{
string text = $"My name is {Name}, I'm {Age} years old. This is my first code '{words}'.";
Console.WriteLine(text);
}
}