c# - Add to a List where some elements are already present -
I have a list in which some elements already exist and before trying to add before. I retrieve the machine name and type, and then use the name of the machine to collect information on the machine.
Here my object is:
public string hostname; Public string master type; Public string oswers; Emerged public cDriveFreeSpace; Public string sqlversion; Public string; Public string adobeVersion; Public overall RAM; Public string processor details; Public string physical processor; Public string logiccore processor; Public emerging memories; Public listing & lt; SystemTools.LogicalDriveInfo & gt; Drive = new list & lt; SystemTools.LogicalDriveInfo & gt; (); Public string OSArchitecture; Public string DotNetVersion;
First of all I would like hostname and soft type:
list & lt; Machines & gt; Results = New list & lt; Machines & gt; (); Foreach (DataRable.Rows in DataRow dr) {result.Add (new machines ((dr.IsNull ("HostName")? "": Dr ["HostName"]). ToString (), dr ["machinetype"]. ToString ())); } Return results;
Whatever I want is for every machine name that I have removed and withdrawn the information listed. I have already got methods to do this already, but I have confused myself on how to add these elements in a proper way.
I was thinking something like the following: I want to avoid creating a new machine type because it can delete hostname and marginize ; MachineList.Count; I ++) {machineList.insert (i, ????) // I want to add it to each element, do this}
As an additional bonus if any An example of using the nested list can provide an example, because I will also need to implement the list drive because machines have multiple drives. Any help is appreciated because IM is stuck something, thanks.
You are trying to edit the objects in the current list, do not add more objects.
foreach (different machine in machine machine) {machine.osVersion = "...."; }
If you need to use index for some reasons:
for (int i = 0; i
Comments
Post a Comment