I have a scenario where there is a dictionary that might or might not have a key value at a given time. I am presently testing to see if the value exists in the following manner
Here is an example for you
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
Dictionary test = new Dictionary();
test.Add("one", "value");
//
// Use TryGetValue to avoid KeyNotFoundException.
//
string value;
if (test.TryGetValue("two", out value))
{
Console.WriteLine("Found");
}
else
{
Console.WriteLine("Not found");
}
}
}