How to Assign an object to the hastable value in C# -


here code

class program {      public static iadxvoice adxvoice1 = new envox.adxvoice.adxvoice();      static void main(string[] args)     {          hashtable objhashmap = new hashtable();         objhashmap.add(8533, adxvoice1);         icollection keytest = objhashmap.values;         icollection keytest1 = objhashmap.keys;          foreach (int key in objhashmap.keys)         {             console.writeline("{0}, {1}", key, objhashmap[key]);             //console.writeline("{0}, {1}", key, objhashmap[key]);             adxvoice obj = objhashmap[key];// getting convert type error cannot implicitly convert type 'object' 'envox.adxvoice.adxvoice'. explicit conversion exists (are missing cast?)              console.readkey();         }     } } 

in above code not able assign hashtable value new object created dll used in code.

my requirement taking objects in hashtable , @ needed time want assign in other places example shown in above code.

you need provide type cast information. objhashmap[key] returns plain objects must cast them.

this code might throw exceptions. casting delicate operation. if cast applied different type, statement throw invalidcastexception. can avoid using or as-statements.

cast below:

adxvoice obj= objhashmap[key] adxvoice; 

refer below link know how use hashtable correctly:
c# hashtable
hashtable class


Comments

Popular posts from this blog

c - CUDA code not processing if block properly -

oracle11g - get root domain from url Oracle sql regex_substr -

xcode - Swift Playground - Files are not readable -