Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem Sorting List
Message
De
15/06/2010 02:41:10
 
 
À
15/06/2010 00:39:37
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01468908
Message ID:
01468921
Vues:
31
>The type in your List must implement the IComparable interface in order for the Sort to be able to work. I just checked and ServiceController does not seem to implement that interface ... so I don't think that's going to work for you at all.

Just write your own (see my reply to Kevin) :-}

>
>I can think of three workarounds off the top of my head (haven't tried either one):
>
>1) Have two Lists, one that is simply a list of names of the services that you can sort, then of course you'd have to find the corresponding service in your Services list.
>
>2) Use a Dictionary or a SortedDictionary, where the Key is the ServiceName and the Value is the actual Service class.
>
>3) Use a SortedList.
>
>
>~~Bonnie
>
>
>
>>I have loaded a list with Windows Services:
>>
>>
>>public static List<ServiceController> GetAllServices()
>>{
>>    ServiceController[] Temp = ServiceController.GetServices();
>>    List<ServiceController> Services = new List<ServiceController>(Temp);
>>    Services.Sort();
>>
>>    return Services;
>>}
>>
>>
>>The Sort line throws the error "Failed to compare two elements in the array." Google hits are obscure on this. Anyone know what this is about?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform