Jef
✅ C# Data structure selection
Hello! I am currently trying to write a program and am having difficulty selecting the best way of storing information collected from a CSV file. The CSV contains server related information such as “server name”, “owner”, “date”.
EX/
Name,date,owner,…
AppServer,date,owner,…
DBServer,date2,owner2,…
….(n) for a list of unknown length
I was investigating creating a server object and creating an instance for each server where:
Server server1 = new Server;
Server server2 = new Server;
But I was unable to find a way to make this work as I do not know how many servers will be in the CSV
I attempting looking for a way to put a variable in the name of the object as so:
Server server_name_variable = new Server;
Where I iterate through server_name_variable, assigning the servers actual name as the instance name, but it appears that variable/object names must be known before compile time, so this would not work in c#
I looked into a dictionary class of keys/values, but each CSV row will have a significant number of independent values corresponding to the key, and from my understanding, dictionary is 1 key per 1 pair. So this would not work.
I would like to be able to call methods on particular values in the data structure eg, Server1.Reboot, and it would kick off a reboot
I was really trying to find the best class structure to do this, but I have yet to find a way to make this work using classes. If anyone could guide me in some direction or some examples of a similar type of structure I would much appreciate it. Let me know if I need to elaborate on anything to make the question more clear.
Thanks!
11 replies