I think those with even a slight grasp on basic string manipulation, loops and dictionaries can work out how to populate a Dictionary from a String such as this:
Black:#00000|Green:#008000| (where "Black" is the Key and "#000000" is the Value)
But what is the most 'elegant' way of doing it in your opinion? What is the most efficient/more concise coding I can use to achieve it? So far I have:
public static Dictionary<String, String> ThemeColors
{
get
{
Dictionary<String, String> themeColors = new Dictionary<string, string>();
foreach (String colorAndCode in GetSettingByName("ThemeColors").ToString().Split('|'))
{
themeColors.Add(colorAndCode.Split(':').First(), colorAndCode.Split(':').Last());
}
return themeColors;
}
}
GetSettingByName("ThemeColours") returns the string above (in Bold).
It's functional obviously, it all works, but I want to make sure I'm beginning to think beyond this now and working out the best way of doing things rather than just getting it working.
Can I use a yield on the Dictionary loop for example??