Ahmed
Ahmed

Reputation: 305

Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'System.String'

I have resource Resource1 have many strings doc1,doc2,...etc i want to retrieve all in this resource in list i make the following code but give me an exception when go to foreach loop this is my code

     ResourceSet resourceSet =  Resource1.ResourceManager.GetResourceSet(
CultureInfo.CurrentUICulture, true, true);
    List<string> Data_set = new List<string>();

foreach (string xs in resourceSet)
        {
            Data_set.Add(xs);

        }
        listBox1.DataSource = Data_set;

Upvotes: 3

Views: 7152

Answers (1)

vincentp
vincentp

Reputation: 1433

You can't cast DictionaryEntry to string, but you can get its Key or Value:

foreach (DictionaryEntry xs in resourceSet)
{
    Data_set.Add(xs.Key + " " + xs.Value);
}

Upvotes: 6

Related Questions