I have an array of objects that I sort by type. Within that array is a set of objects of one type that are already in their preferred relative order. After the sort, these objects are grouped together, but no longer in the same order. I am using the sort a follows
Array.Sort(shapes, GetVisualComparer());
I have looked for a sort method that promises to preserve original order, but have found nothing.
I will note that I have a workaround, but it adds unnecessary confusion to the code, and does not address the general problem if it comes up in the future.
GroupBypreserves the order, that is guaranteed. "The IGrouping<TKey, TElement> objects are yielded in an order based on the order of the elements in source that produced the first key of each IGrouping<TKey, TElement>. Elements in a grouping are yielded in the order that the elements that produced them appear in source."