You can also create extension method like below:
public partial class Page2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Hashtable hashtable = new Hashtable();
hashtable.AddIfNotExists("Time1", Convert.ToDateTime("11/18/2016 3:43:33 PM"));
hashtable.AddIfNotExists("Time2", Convert.ToDateTime("11/18/2016 3:43:34 PM"));
hashtable.AddIfNotExists("Time3", Convert.ToDateTime("11/18/2016 3:43:33 PM"));
hashtable.AddIfNotExists("Time4", Convert.ToDateTime("11/18/2016 3:43:35 PM"));
}
}
public static class Extension
{
public static void AddIfNotExists(this Hashtable hash, string key1, DateTime value2)
{
if (hash.ContainsKey(key1) == false && Convert.ToDateTime((hash[key1])) != value2)
{
hash.Add(key1, value2);
}
}
}