Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get list string from Hashtable?

I don’t how to get list values

Hashtable hshTable = new Hashtable();
List<string> l= new List<string>();
l.Add("string1");
l.Add("string2");
hshTable.Add("1",l);

try

string temp= hshTable["1"][0];

error Cannot apply indexing with [] to an expression of type ‘object’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

From the documentation and error message, Hashtable.Item[Object] returns object.

public virtual object? this[object key] { get; set; }

You should cast the value as List<string> type before getting the value by index.

string temp= ((List<string>)hshTable["1"])[0];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading