且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将对象列表添加到另一个列表C#

更新时间:2023-01-08 12:16:08

您需要识别相应的人员实例 - 我不知道您如何存储它们,您没有表明:每次添加日期时都会重新创建Person实例,因此它不能存在。



但是一旦你拥有了Person,就很容易:

You need to identify the appropriate person instance - and I have no idea how you are storing them, you don't show that: the Person instance is created anew each time you add a a date, so it can't be there.

But once you have the Person, it's easy:
myPerson.numberOfDates.add(dates);





BTW:尽量避免将事物命名为复数,除非它们是一个集合:Dates是一个单日期存储对象,因此它应该是Date,而People应该是人 - 但你似乎也有一个班级......这让人感到困惑!



BTW: try to avoid naming things as plurals unless they are a collection: "Dates" is a single date storage object, so it should be "Date", and "People" should probably be "Person" - but you appear to have a class for that as well...which gets confusing!