在一个糟糕的界面中,我们有以下问题:
以 userIdList[i] 始终包含 userNameList[i] 的用户ID为限制条件,新的要求是按名称对用户进行排序: 我将采取这两个列表,按名称排序,并返回两个列表,其中前述限制仍然有效。
当然,我可以自己实现一个排序功能,但我认为单行LINQ语句可以做得更好?我已经达到了:
int[] userIdList; // ids of all users to display
string[] userNameList; // names of all users to display
以 userIdList[i] 始终包含 userNameList[i] 的用户ID为限制条件,新的要求是按名称对用户进行排序: 我将采取这两个列表,按名称排序,并返回两个列表,其中前述限制仍然有效。
当然,我可以自己实现一个排序功能,但我认为单行LINQ语句可以做得更好?我已经达到了:
userNameList.Zip(userIdList, (name, id) => new {name, id}).OrderBy(a=>a.name).
但是现在我不知道如何再次解压列表...