Autor Beitrag
daeve
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 116
Erhaltene Danke: 3

Windows (XP Pro, 7 Ultimate x64)
C#,WPF,Java,ASP.Net, VS 2010 Ultimate (x86)
BeitragVerfasst: Sa 22.10.11 14:44 
Hallo zusammen

ich muss dieses String Array nach den int Array sortiern.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
static void CombinedSelect()
        {
            int[] numbers = { 5413986720 };
            string[] strings = { "zero""one""two""three""four""five""six""seven""eight""nine" };

           
            IEnumerable<string> zahlen = from z in strings
                                         orderby numbers
                                         select z;

       }


also die die reihenfolge der neun List ( five,four,one, usw. wäre)

kann mir da jemand helfen ?

Gruss David
GRuss David
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 22.10.11 14:55 
Hi!

Die Elemente des numbers-Array sind doch direkt die Indizes der Elemente, die Du aus dem strings-Array selektieren musst.

Grüße,
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
daeve Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 116
Erhaltene Danke: 3

Windows (XP Pro, 7 Ultimate x64)
C#,WPF,Java,ASP.Net, VS 2010 Ultimate (x86)
BeitragVerfasst: Sa 22.10.11 15:03 
Ja das ist so ;) ... stehe auf einem riesen Schlauch.

kannst du mir schnell weiterhelfen ?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 22.10.11 15:06 
Du gehst das numbers-Array Element für Element durch, zum Beispiel mit einer Schleife. Diese Elemente verwendest Du jeweils als Indizes, um auf das strings-Array zuzugreifen. Damit hast Du die Elemente des strings-Array in der richtigen Reihenfolge.

Es geht auch über LINQ, aber das fördert nicht das Verständnis, was gemacht wird.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
daeve Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 116
Erhaltene Danke: 3

Windows (XP Pro, 7 Ultimate x64)
C#,WPF,Java,ASP.Net, VS 2010 Ultimate (x86)
BeitragVerfasst: Sa 22.10.11 15:11 
ja mit einer Schleife wäre das kein Problem, ich muss das aber leider mit LinQ machen.....
( wir sind bei LINQ und Lambda in der schule)
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 22.10.11 15:20 
Naja, mit LINQ ist es nicht so viel anders: Mithilfe der Elemente des numbers-Array selektierst Du Elemente des strings-Array.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
daeve Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 116
Erhaltene Danke: 3

Windows (XP Pro, 7 Ultimate x64)
C#,WPF,Java,ASP.Net, VS 2010 Ultimate (x86)
BeitragVerfasst: Sa 22.10.11 15:24 
Ja soweit bin ich bereits, aber ich kann meine Gedanken nicht auf den Code übertragen( habe es mit index, key, value) probiert aber komme auf keine richtige lösung.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 22.10.11 15:29 
Dann zerleg das Problem doch: Selektiere mit LINQ erst einmal nur die Element des numbers-Array. Dann sehen wir weiter ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".

Für diesen Beitrag haben gedankt: daeve
daeve Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 116
Erhaltene Danke: 3

Windows (XP Pro, 7 Ultimate x64)
C#,WPF,Java,ASP.Net, VS 2010 Ultimate (x86)
BeitragVerfasst: Sa 22.10.11 15:35 
ausblenden C#-Quelltext
1:
2:
IEnumerable<string> zahlen = from n in numbers
                             select strings[n];


ich habe die Arrays verkehrt herum in meine LINQ abfrage gesteckt...

dank deinem Satz zuerst mal nur numbers-Array hat es dann klick gemacht ;) thx