Nightfall Geschrieben 28. April 2009 Geschrieben 28. April 2009 Hi! Ich habe folgendes Problem: Ich erstelle ein Struct: public struct CommandStruct { public string aCategory; // Eine Category kann mehrere Commands haben. public string aCommand; // Ein Command kann nur eine Category haben. (Jedes Command ist eingigartig) public string aShortcut; // Ein Shortcut kann nur zu einem Command gehören. public string aToolTip; // Mehrere Commands können einen gleichen ToolTip haben. public image aImage; // Mehrere Commands können sich ein Image teilen. } Nun mache ich mir eine Liste daraus: List<CommandStruct> m_CommandStructList = new List<CommandStruct>(); Ich möchte nun zum Beispiel folgendes wissen: Ich habe eine Category und das dazugehörige Command. Nun möchte ich den ShortCut dazu wissen. Anderes Beispiel: Ich habe eine Category und möchte die jeweiligen Commands dazu wissen. Kann ich das mit der Liste machen? Wenn nicht: Gibt es einen anderen (besseren) Weg? Habe es auch mal mit mehreren Dictionarys probiert. Das hat aber den Nachteil das man immer nur einen Key und ein Value hat. Sorry falls es ein wenig kompliziert geschrieben ist. :hells: Gruß Nightfall
Guybrush Threepwood Geschrieben 28. April 2009 Geschrieben 28. April 2009 class Program { public struct CommandStruct { public string aCategory; // Eine Category kann mehrere Commands haben. public string aCommand; // Ein Command kann nur eine Category haben. (Jedes Command ist eingigartig) public string aShortcut; // Ein Shortcut kann nur zu einem Command gehören. public string aToolTip; // Mehrere Commands können einen gleichen ToolTip haben. public string aImage; // Mehrere Commands können sich ein Image teilen. } static void Main(string[] args) { List<CommandStruct> m_CommandStructList = new List<CommandStruct>(); m_CommandStructList.Add(new CommandStruct() { aCategory = "Cat1", aCommand = "Com1", aShortcut = "Strg+A", aImage = "Image1", aToolTip = "fdbgio" }); m_CommandStructList.Add(new CommandStruct() { aCategory = "Cat1", aCommand = "Com2", aShortcut = "Strg+B", aImage = "Image2", aToolTip = "fdbgfhrjio" }); m_CommandStructList.Add(new CommandStruct() { aCategory = "Cat2", aCommand = "Com3", aShortcut = "Strg+C", aImage = "Image1", aToolTip = "trh" }); m_CommandStructList.Add(new CommandStruct() { aCategory = "Cat2", aCommand = "Com4", aShortcut = "Strg+D", aImage = "Image2", aToolTip = "fdbgio" }); m_CommandStructList.Add(new CommandStruct() { aCategory = "Cat2", aCommand = "Com5", aShortcut = "Strg+E", aImage = "Image1", aToolTip = "fdbfjjgio" }); var shortcut = from com in m_CommandStructList where com.aCategory == "Cat1" && com.aCommand == "Com2" select com.aShortcut; Console.WriteLine(shortcut.First()); var commands = from com in m_CommandStructList where com.aCategory == "Cat2" select com; foreach (CommandStruct cs in commands) { Console.WriteLine(cs.aCommand); } } }[/PHP]
TDM Geschrieben 28. April 2009 Geschrieben 28. April 2009 Habe es auch mal mit mehreren Dictionarys probiert. Das hat aber den Nachteil das man immer nur einen Key und ein Value hat. List<CommandStruct> als Value?! :floet: Aber ich denke das Linq-Beispiel vom Piraten ist da performanter, einfacherer usw.
Nightfall Geschrieben 28. April 2009 Autor Geschrieben 28. April 2009 Ganz großes danke schön an den Piraten. :uli
Empfohlene Beiträge
Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren
Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können
Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!
Neues Benutzerkonto erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde Dich hier an.
Jetzt anmelden