Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I have home object : id , FirstName, Lastname, Fees[ ]
id
FirstName
Lastname
Fees[ ]
Fees is object contain Amount description DueDate ...
home object include the Fees array
I have list of homes and every home has array/list from fees
I need to sort the fees depend on the Duedate in each object
for (int i = 0; i < homes.Length; i++) { homes[i].Fees = homes[i].Fees.OrderBy(si => si.DueDate).ToArray(); }
Can I find one statement instead of four statements?
Can I find one statement instead of three statements?
That should rarely be your goal.
However; you say that Fees is an array; if that is the case, you can avoid some work by sorting in-place rather than creating a clone of the array:
Fees
foreach(var home in homes) { Array.Sort(home.Fees, (x,y) => x.DueDate.CompareTo(y.DueDate)); }
我可以找到一个语句而不是三个语句吗?
这应该很少是你的目标。
然而; 你说那Fees是一个数组;如果是这种情况,您可以通过就地排序而不是创建数组的克隆来避免一些工作: