Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem Sorting List
Message
From
15/06/2010 02:41:10
 
 
To
15/06/2010 00:39:37
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01468908
Message ID:
01468921
Views:
30
>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?
Previous
Reply
Map
View

Click here to load this message in the networking platform