Usually when using Linq, I usually filtered out empty / null entries using Where or similar. However, I need to order the list according to several criteria and keep all the elements in the list, but in order.
The following only works when .Dimension1.Count > 0for all items in the list
var orderedList = mList.Elements
.OrderBy(x => x.Property1)
.ThenBy(x => x.Property2)
.ThenBy(x => x.Property3.Dimension1[0].Value2)
.ToList();
If any of the elements has Dimension1.Count == 0, then I get an error:
'The index was out of range. Must be non-negative and smaller than the size of the collection. ''
The array is not expected to be sized.
Is there a way to make this work when the list contains items that have .Dimension1.Count = 0?
Note that it Dimension1[0].Value2is of type double.