StringDictionary Item Property for C#

  • Thread starter Thread starter Wamiq Ansari
  • Start date Start date
W

Wamiq Ansari

Hi!,
I am trying to add a value to a StringDictionary using its Item Property in
C#. However this throws an expection as follows:
Cannot implicitly convert type 'Component.TemplateComponent' to 'string'.

The method I am using is as follows:

private StringDictionary componentList = new StringDictionary();

public void addComponent(TemplateComponent docComponent)

{

componentList["AAA"] = docComponent;

}

Remember the main idea is to avoid using StringDictionary.Add() method and
use C# indexer property. The above example works if I use a Hashtable
instead of StringDictionary. Is there anything special about
StringDictionary that i'm missing.

Help!!!!

Wamiq
 
Hi Wamiq,
StringDictionary class maps string keys to string values.
In other words that dictionary is strongly typed for string objects
You can't just add 'Component.TemplateComponent object because it is not a
string.

HTH
B\rgds
100
 
Oh, I wasn't aware of that. Thanks for clearing that point

regards,

wamiq

100 said:
Hi Wamiq,
StringDictionary class maps string keys to string values.
In other words that dictionary is strongly typed for string objects
You can't just add 'Component.TemplateComponent object because it is not a
string.

HTH
B\rgds
100

Wamiq Ansari said:
Hi!,
I am trying to add a value to a StringDictionary using its Item Property in
C#. However this throws an expection as follows:
Cannot implicitly convert type 'Component.TemplateComponent' to 'string'.

The method I am using is as follows:

private StringDictionary componentList = new StringDictionary();

public void addComponent(TemplateComponent docComponent)

{

componentList["AAA"] = docComponent;

}

Remember the main idea is to avoid using StringDictionary.Add() method and
use C# indexer property. The above example works if I use a Hashtable
instead of StringDictionary. Is there anything special about
StringDictionary that i'm missing.

Help!!!!

Wamiq
 
Back
Top