C#数组存入引用类型
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ControlProject { class User { public string Name { get; set; } public int Age { get; set; } public User() { } public User(string name,int age) { this.Name = name; this.Age = age; } } class Program { static void Main(string[] args) { User u1 = new User("神秘藏宝室",26); User u2 = new User("神秘", 26); User u3 = new User("藏宝室", 26); User[] myUser = { u1, u2, u3 }; foreach(User u in myUser) { Console.WriteLine("用户:{0},年龄:{1}", u.Name, u.Age); } } } }
文章对您有帮助,开心可以打赏我,金额随意,欢迎来赏!
需要电子方面开发板/传感器/模块等硬件可以到我的淘宝店逛逛