c# - Sorting array by item type -


i have array of objects sort type. within array set of objects of 1 type in preferred relative order. after sort, these objects grouped together, no longer in same order. using sort follows

array.sort(shapes, getvisualcomparer());

i have looked sort method promises preserve original order, have found nothing.

i note have workaround, adds unnecessary confusion code, , not address general problem if comes in future.

make copy of original array. then, make comparer compare original indexes of elements if type equal.

i don't know on base type sorting, sorting name, this:

public class typecomparer : icomparer<type> {     public int compare(type x, type y)     {         int result = stringcomparer.invariantculture.compare(x.name, y.name);         if (result == 0)         {             result = array.indexof(originalarray, x).compareto(array.indexof(originalarray, y));         }         return result;     } } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -