Student here.
Working on a current C# project.
I have to create a List<Card>
of playing cards, and a Dictionary<string, List<Card>>
.
List gets created independently, and the dictionary holds collections of cards. Cards can be added or removed from collections.
I'm having trouble creating a dictionary key based off user input
The error is while the program is running, and I type in the name of the key I want to create.
Object reference not set to an instance of an object.
Here is the code block:
Console.Write("What is the name of this collection? ");
string collectionName = Console.ReadLine();
bool found = currentManager.Collections.ContainsKey(collectionName);
if (!found)
{
currentManager.Collections.Add(collectionName, null);
}
else
Console.WriteLine("That collection name has already been used.");
I am using a CollectionManager class, with my Dictionary named _collections. This is being called here:
public Dictionary<string, List<Card>> Collections
{
get
{
return _collections;
}
set
{
_collections = value;
}
}