I am initialising a new Dictionary and putting each key one by one like so:
igData = data.Select(x => new Dictionary<string, string> { ["Date"] = x.GetValueOrDefault("DATE"), ["SP"] = x.GetValueOrDefault("SP"), ["IG"] = x.GetValueOrDefault("IG")}).ToList(); This is fine but the rest of the keys need to be headers that I have created in List<string> headers
Is it possible to add this list of headers within the initialisation above? Something like this:
igData = data.Select(x => new Dictionary<string, string> { ["Date"] = x.GetValueOrDefault("DATE"), ["SP"] = x.GetValueOrDefault("SP"), ["IG"] = x.GetValueOrDefault("IG"), headers.Select(y => new KeyValuePair<string, string> (y, x.GetValueOrDefault["IG"])).ToList(); I understand the value is the same but that is intended. Is the above possible or is this something I would have separate. It would be ideal to do it in the above since I have access to the value from the data collection.
data/headers? Why do you create so many dictionaries?ToDictionaryextension.List<Dictionary<string, string>>and headers isList<string>.