none
Trace - Dictionary - long Liste RRS feed

  • Frage

  •  

     Hallo,

    DictionaryVariables.Add(key, new List<long>(OccurList[FromParent]));

     gibt es schnelle Möglichkeiten, die obige Anweisung, schnell in einen String zu bekommen, ohne
     durchlaufen der Liste.

     Also so.
     - Componente01 - 1,0,0,0,1
     - Componente02 - 0,1,1,0,0
     - Componente03 - 0,0,0,1,0

     Trace.Writeline("key {0}, Vorkommen {1}", key, XXXXXXXXXXX )

    Grüße Sandra


      
    Dienstag, 21. Juni 2016 16:35

Antworten

  • Hallo Sandra,

    vielleicht so:

    Dictionary<string, List<long>> theDictionary = new Dictionary<string, List<long>>();
    theDictionary.Add("component01", new List<long>(new long[] { 0, 1, 1, 0, 1 }));
    theDictionary.Add("component02", new List<long>(new long[] { 1, 1, 1, 0, 1 }));
    theDictionary.Add("component03", new List<long>(new long[] { 0, 1, 1, 1, 1 }));

    string msg = string.Join(Environment.NewLine, theDictionary.Select(
     dictionaryItem =>    "-" + dictionaryItem.Key + "-" + string.Join(
     ",", dictionaryItem.Value.Select(listItem => listItem.ToString()).ToArray())).ToArray());

    Console.WriteLine(msg);
    Console.ReadKey();
    return;

    Also, die 5.te Zeile müsste liefern, was du gefragt hast (ohne durchlaufen der Liste...)

    Gruß





    • Bearbeitet K. Pater Mittwoch, 22. Juni 2016 12:39 kleine Anpassungen :-)
    • Als Antwort markiert Sandra Bauer Mittwoch, 22. Juni 2016 17:40
    Mittwoch, 22. Juni 2016 10:00

Alle Antworten

  • Hallo Sandra,

    vielleicht so:

    Dictionary<string, List<long>> theDictionary = new Dictionary<string, List<long>>();
    theDictionary.Add("component01", new List<long>(new long[] { 0, 1, 1, 0, 1 }));
    theDictionary.Add("component02", new List<long>(new long[] { 1, 1, 1, 0, 1 }));
    theDictionary.Add("component03", new List<long>(new long[] { 0, 1, 1, 1, 1 }));

    string msg = string.Join(Environment.NewLine, theDictionary.Select(
     dictionaryItem =>    "-" + dictionaryItem.Key + "-" + string.Join(
     ",", dictionaryItem.Value.Select(listItem => listItem.ToString()).ToArray())).ToArray());

    Console.WriteLine(msg);
    Console.ReadKey();
    return;

    Also, die 5.te Zeile müsste liefern, was du gefragt hast (ohne durchlaufen der Liste...)

    Gruß





    • Bearbeitet K. Pater Mittwoch, 22. Juni 2016 12:39 kleine Anpassungen :-)
    • Als Antwort markiert Sandra Bauer Mittwoch, 22. Juni 2016 17:40
    Mittwoch, 22. Juni 2016 10:00
  • Hallo Klaus,
    ich konnte es relativ einfach lösen, macht was ich will. Muss man auch wissen, dass es so einfach ist.
    Format("    -> The occurring position {0}", string.Join(";", dicItem.Value));


    Bei einem anderen Objekt mußte ich ToString überschreiben, dann ging das auch.
    Gruß, Sandra
    Mittwoch, 22. Juni 2016 17:40