object

mac2024-03-11  31

01.重写ToString()

using System; using static System.Console; namespace Array { class Program { static void Main(string[] args) { People people=new People(5,"一休"); WriteLine(people.ToString()); ReadKey(); } } class People { public int Age { get; set; } public string Name { get; set; } public People(int age, string name) { this.Age = age; this.Name = name; } public override string ToString() { return $"名字:{Name},年龄:{Age}"; } } }

最新回复(0)