J’ai ce qui suit:
En boucle par exemple:
GlobalSsortingngs = new List(); for(x=1;x<10;x++) { localStrings = new List; localSsortingngs.Add("some value"); localSsortingngs.Add("some value"); // Want to append localSsortingngs to GlobalSsortingngs as easily as possible }
GlobalSsortingngs.AddRange(localSsortingngs);
Remarque: Vous ne pouvez pas déclarer l’object liste à l’aide de l’interface (IList).
GlobalSsortingngs.AddRange(localSsortingngs);
Je pense que ça marche.
Il y avait une faute de frappe. J’ai ajouté cette ligne pour sortir du problème “modification de caractère unique non autorisé”.
Essayez la méthode AddRange:
GlobalSsortingngs.AddRange(localSsortingngs);
Avec linq
var newList = GlobalSsortingngs.Append(localSsortingngs)
Voici mon exemple:
private List m_machinePorts = new List (); public List machinePorts { get { return m_machinePorts; } } Init() { // Custom function to get available ethernet ports List localEnetPorts = _Globals.GetAvailableEthernetPorts(); // Custome function to get available serial ports List localPorts = _Globals.GetAvailableSerialPorts(); // Build Available port list m_machinePorts.AddRange(localEnetPorts); m_machinePorts.AddRange(localPorts); }
si tu veux te “lacérer” 🙂
ListGlobalSsortingngs = new List (); for(int x=1; x<10; x++) GlobalStrings.AddRange(new List { "some value", "another value"});