Sort two Lists together as one?

前端 未结 7 2071
执笔经年
执笔经年 2020-12-07 01:30

I have two List which I am accessing by index (e.g. Name[10], Date[10]). They\'re closely tied, so Name[10] is related to Date[1

7条回答
  •  佛祖请我去吃肉
    2020-12-07 01:58

    It sounds like you're fighting against doing the obvious solution which involves a little bit of upfront work: creating a type to encapsulate the name/date pair.

    That's absolutely what you should do. Then you can have one list, sort it by name or by date or whatever you want, and you never need to worry about the two lists getting out of sync etc.

    If your Results class doesn't do anything apart from contain those two lists, you can actually end up with the same number of types - you can ditch Results entirely, in favour of List where Result has a name and a date.

提交回复
热议问题