Problema de ordenamiento

(1/2) > >>

luis456:
He probado y reprobado ordenar la salida en este codigo de menor a mayor y siempre me da error en ejecucion probando todas las variables y probando en diseño del listbox en false o true y me sigue fallando.

Código
Dim Re As New Random
Dim Result22aa55e As IEnumerable(Of Integer) =
             (
                 (Result1.Concat(Result2).Concat(Result3).
           Distinct.
           Select(Function(Value As Integer)
                      Return If(Value < MAX, Value, Rand.Next(0, MAX))
                  End Function))
        )
 
       Dim selecctedValues23aa As IEnumerable(Of Integer) = Result22aa55e.Take(11)
 
       '  Array.Sort(selecctedValues23aa)
       ' ListBox3.Sorted = True
 
     Me.ListBox3.Items.AddRange(selecctedValues23aa.Cast(Of Object).ToArray)  

el code funciona bien pero me muestra los numeros desordenados

Luis

Eleкtro:
Utilizando las extensiones LINQ:
IEnumerable.OrderBy

(Lee el ejemplo en Vb.Net que hay en esa misma página)

Saludos!

luis456:
Cita de: Eleкtro en 11 Marzo 2015, 14:29 pm

Utilizando las extensiones LINQ:
IEnumerable.OrderBy

(Lee el ejemplo en Vb.Net que hay en esa misma página)

Saludos!


Te refieres a esta cosa :)

Código
Structure Pet
       Public Name As String
       Public Age As Integer
   End Structure
 
   Sub OrderByEx1()
       ' Create an array of Pet objects.
       Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8}, _
                            New Pet With {.Name = "Boots", .Age = 4}, _
                            New Pet With {.Name = "Whiskers", .Age = 1}}
 
       ' Order the Pet objects by their Age property.
       Dim query As IEnumerable(Of Pet) = _
           pets.OrderBy(Function(pet) pet.Age)
 
       Dim output As New System.Text.StringBuilder
       For Each pt As Pet In query
           output.AppendLine(pt.Name & " - " & pt.Age)
       Next
 
       ' Display the output.
       MsgBox(output.ToString())
   End Sub
 
   ' This code produces the following output:
   '
   ' Whiskers - 1
   ' Boots - 4
   ' Barley - 8

luis



Eleкtro:
Cita de: luis456 en 11 Marzo 2015, 14:42 pm

Te refieres a esta cosa :)

Si, fíjate bien:
Cita de: MSDN

Código
Structure Pet
       Public Name As String
       Public Age As Integer
   End Structure
 
   Sub OrderByEx1()
       ' Create an array of Pet objects.
       Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8}, _
                            New Pet With {.Name = "Boots", .Age = 4}, _
                            New Pet With {.Name = "Whiskers", .Age = 1}}
 
       ' Order the Pet objects by their Age property.
       Dim query As IEnumerable(Of Pet) = _
           pets.OrderBy(Function(pet) pet.Age)
 
       Dim output As New System.Text.StringBuilder
       For Each pt As Pet In query
           output.AppendLine(pt.Name & " - " & pt.Age)
       Next
 
       ' Display the output.
       MsgBox(output.ToString())
   End Sub
 
   ' This code produces the following output:
   '
   ' Whiskers - 1
   ' Boots - 4
   ' Barley - 8


Lo suyo es que entiendas esa "cosa" a la que te estás refiriendo, o al menos su utilización.

Saludos

luis456:
Cita de: Eleкtro en 11 Marzo 2015, 14:44 pm

Si, fíjate bien:
Lo suyo es que entiendas esa "cosa" a la que te estás refiriendo, o al menos su utilización.

Saludos


Jejeje pues npi por ahora y te cuento tendría que hacerlo 20 veces que son las rutinas que tengo en el codigo la que puse arriba, pensaba que con una cosa corta lo podria arreglar jejje

Luis

Navegación

[0] Índice de Mensajes

[#] Página Siguiente