Is it possible to add custom object as a key in HashTable,if so how to retrieve the stored value?
Yes. Its certainly possible to store custom object as a key in hashtable. Since hashtable key is of type "object", we can use any type of object as key. I didn't find any usage with adding custom object as key. I presume this question is to test candidate analytic skills.
Eg:
Hashtable ht = new Hashtable(); Customer objCustomer = new Customer(); objCustomer.CustomerID = 1; objCustomer.CustomerName = "Ram"; ht.Add(objCustomer, objCustomer); Customer obj = ht[objCustomer] as Customer;
Read More..   [32134 clicks]
Published under: C# Interview Questions and Answers · · · ·