You can use Dictionary<>.ContainsKey to check if a key exists, so you would do it like this:
if (dicThreatPurgeSummary.ContainsKey(Group))
{
if (dicThreatPurgeSummary[Group].ContainsKey(Month))
{
// dicThreatPurgeSummary[Group][Month] exists
}
}
Note that it might be better to use a two dimensional key instead of cascading two dictionaries. That way you won’t need to care to add a new dictionary every time you use a new key for the first level, and you would have all values in the same dictionary, allowing you to iterate over the values or check for values existance.
You could use a tuple for that:
var dicThreatPurgeSummary = new Dictionary<Tuple<int, int>, int>();
dicThreatPurgeSummary.Add(new Tuple<int, int>(Group, Month), Count);
// accessing the value
int a = dicThreatPurgeSummary[new Tuple<int, int>(Group, Month)];
// checking for existance
if (dicThreatPurgeSummary.ContainsKey(new Tuple<int, int>(Group, Month)))
{
// ...
}
Using a prettier subtype
(untested)
class IntIntDict<T> : Dictionary<Tuple<int, int>, T>
{
public T this[int index1, int index2]
{ get { return this[new Tuple(index1, index2)]; } }
public bool ContainsKey (int index1, int index2)
{
return ContainsKey(new Tuple(index1, index2));
}
public void Add (int index1, int index2, T value)
{
Add(new Tuple(index1, index2), value);
}
// ...
}
And then you could just use it like this:
var dicThreatPurgeSummary = new IntIntDict<int>();
dicThreatPurgeSummary.Add(Group, Month, Count);
// accessing the value
int a = dicThreatPurgeSummary[Group, Month];
// checking for existance
if (dicThreatPurgeSummary.ContainsKey(Group, Month))
{
// ...
}