Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Fastest way to sort a collection
Message
De
31/01/2013 04:27:18
 
 
À
30/01/2013 18:52:17
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01564757
Message ID:
01564808
Vues:
48
This message has been marked as a message which has helped to the initial question of the thread.
>>If you know your collection is in ascending order and you want it descending, just reverse it (http://msdn.microsoft.com/en-us/library/b0axc2h2%28v=vs.90%29.aspx). Otherwise you can use the sort method (http://msdn.microsoft.com/en-us/library/3da4abas%28v=vs.90%29.aspx) to sort it, although you might need to create your own comparer. Or you could change your collection to a SortedList (http://msdn.microsoft.com/en-us/library/ms132319%28v=vs.90%29.aspx) so that the list is created in a sorted order.
>>
>>It might also help to know exactly what type of collection you are using, how you are sorting now that is too slow, and why your collection is composed of single element object arrays instead of strings.
>
>The collection is defined like this:
>
>
>        Public oDirectory As Collection = New Collection
>
>
>The first link mentions the usage of a list approach. This is different in my case.
>
>All collections are built to support undefined number of items. Here is an example:
>
>
>        ' Add a parameter in a container for the data dictionary fields
>        ' expC1 Field
>        ' expO1 Value
>        Private Function ParameterAddDataDictionaryField(ByVal tcField As String, ByVal toValue As Object) As Boolean
>            Dim loParameter(1, 5) As Object
>
>            ' Initialization
>            loParameter(1, 1) = tcField
>            loParameter(1, 2) = toValue
>            loParameter(1, 3) = ""
>            loParameter(1, 4) = ""
>            loParameter(1, 5) = 0
>
>            oParametersDataDictionaryField.Add(loParameter)
>
>            Return True
>        End Function
>
Assuming you want to sort on the first element (tcField):
var result = oParametersDataDictionaryField.OfType<object[]>().OrderBy(x=>x[0]).Reverse();
That said I would probably have used a generic dictionary instead :-}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform