public class ScheduleSelectedItems { private string Ad; public ScheduleSelectedItems(string ad) { Ad = ad; } public override string ToString() { return this.Ad; } }
什么BFree说,稍作修改,使其成为单数而不是复数:
public class ScheduleSelectedItem { private string Ad; public ScheduleSelectedItem(string ad) { Ad = ad; } public override string ToString() { return this.Ad; } }
此外,您需要为列表添加"添加"方法.当你在它的时候,为什么不继承list类:
public class ScheduleSelectedItemsList : List{ }
或者你可以创建一个类型别名:
using ScheduleSelectedItemsList = List;
无论哪种方式,您都可以使用这样的新代码:
class Program { static void Main(string[] args) { var slist = new ScheduleSelectedItemsList() { new ScheduleSelectedItem("Yusuf") }; //write every item to the console, not just the first slist.All(item => Console.Write(item.ToString()) ); Console.ReadKey(); } }