http://www.dotnetperls.com/dictionaryentry
Above website is saying that "DictionaryEntry is used with Hashtable". Also example program is given.
But 3rd program in the following website is using DictionaryEntry without Hashtable. Problem is highlighted. I wish to know the reason for discrepancy.
http://www.dotnetperls.com/exception
using System;
using System.Collections;
class Program
{
static void Main()
{
try
{
// Create new exception.
var ex = new DivideByZeroException("Message");
// Set the data dictionary.
ex.Data["Time"] = DateTime.Now;
ex.Data["Flag"] = true;
// Throw it!
throw ex;
}
catch (Exception ex)
{
// Display the exception's data dictionary.
foreach (DictionaryEntry pair in ex.Data)
{
Console.WriteLine("{0} = {1}", pair.Key, pair.Value);
}
}
Console.ReadKey();
}
}
Loading
VulpesPosted Aug 11, 2013, 4:50 PM
When you enumerate an IDictionary object (with 'foreach' for example) the key/value pairs are returned as DictionaryEntry structures and can be retrieved using its Key and Value properties.
So, in your example, the Data property of an Exception object is being enumerated. As you'll see from the documentation this property returns an IDictionary object (the actual type is unspecified but it appears to be a special kind of Hashtable):
http://msdn.microsoft.com/en-us/library/system.exception.data.aspx
The enumeration therefore returns a series of DataEntry instances which we can then examine and print to the console.
Posted Aug 11, 2013, 5:08 PM