Hey;

I want to store string, ConsoleColor pairs like

dataStructure.Add(new KeyValuePair<string, ConsoleColor>("Red", ConsoleColor.Red))

I tried List but it did not seem to work;

List<KeyValuePair<string, ConsoleColor>> colorList;
            colorList.Add(new KeyValuePair<string, ConsoleColor>("Red", ConsoleColor.Red));
            colorList.Add(new KeyValuePair<string, ConsoleColor>("Yellow", ConsoleColor.Yellow));
            colorList.Add(new KeyValuePair<string, ConsoleColor>("Green", ConsoleColor.Green));
            colorList.Add(new KeyValuePair<string, ConsoleColor>("Blue", ConsoleColor.Blue));
            colorList.Add(new KeyValuePair<string, ConsoleColor>("White", ConsoleColor.White));

with the error "An unhandled exception of type 'System.NullReferenceException' occurred in BrainSalad.exe".

Can you help me with this issue?

You haven't initialised your List.

Also, there is a pre-defined collection for this called "Dictionary" Dictionary<String, ConsoleColor> colorList = new Dictionary<String, ConsoleColor>();

commented: Thanks for the lightning fast and correct reply +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.