I have below data structure:
Which C# data structure is best to store and retrieve these easily?
I want to be able to refer to Dev, Dev.Value1, Dev.Key1, Test, Test.Key1, so on..
Update: I have a json file and as I parse it I get these values. So the number of environments (Dev, Test) will be more like ( Dev, Test, UAT, Stable, Prod). Also the number of Key, Value pairs will be different in each environment. I need to store them separately in a structure to consume them later. As I parse the json I will get an environment (Dev) and all its key, values pairs and then I will get Test followed by all its key, value pairs.
You can make class like this...
public class Environment
{
Dictionary<string, string> KeyValueData { get; set; }
public string Name { get; set; }
public Environment(string name)
{
Name = name;
KeyValueData = new Dictionary<string, string>();
}
public void AddNewData(string key, string value)
{
this.KeyValueData.Add(key, value);
}
}
Usage:
List<Environment> environments = new List<Environment>();
Environment env = new Environment("Test");
env.AddNewData("key1", "value1");
env.AddNewData("key2", "value2");
env.AddNewData("key3", "value3");
Environment env2 = new Environment("Prod");
env2.AddNewData("key1", "value1");
env2.AddNewData("key2", "value2");
env2.AddNewData("key3", "value3");
//...
environments.Add(env2);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments