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.
Hashtable ht = new Hashtable();
Customer objCustomer = new Customer();
objCustomer.CustomerID = 1;
objCustomer.CustomerName = "Ram";
Customer obj = ht[objCustomer] as Customer;
C# Interview Questions and Answers · · · ·