473,569 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StringDictionar y Item Property for C#

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

The method I am using is as follows:

private StringDictionar y componentList = new StringDictionar y();

public void addComponent(Te mplateComponent docComponent)

{

componentList["AAA"] = docComponent;

}

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

Help!!!!

Wamiq

Nov 15 '05 #1
2 4114
100
Hi Wamiq,
StringDictionar y class maps string keys to string values.
In other words that dictionary is strongly typed for string objects
You can't just add 'Component.Temp lateComponent object because it is not a
string.

HTH
B\rgds
100

"Wamiq Ansari" <wa***@msn.co m> wrote in message
news:uV******** ******@TK2MSFTN GP09.phx.gbl...
Hi!,
I am trying to add a value to a StringDictionar y using its Item Property in C#. However this throws an expection as follows:
Cannot implicitly convert type 'Component.Temp lateComponent' to 'string'.

The method I am using is as follows:

private StringDictionar y componentList = new StringDictionar y();

public void addComponent(Te mplateComponent docComponent)

{

componentList["AAA"] = docComponent;

}

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

Help!!!!

Wamiq

Nov 15 '05 #2
Oh, I wasn't aware of that. Thanks for clearing that point

regards,

wamiq

"100" <10*@100.com> wrote in message
news:OI******** *****@TK2MSFTNG P11.phx.gbl...
Hi Wamiq,
StringDictionar y class maps string keys to string values.
In other words that dictionary is strongly typed for string objects
You can't just add 'Component.Temp lateComponent object because it is not a
string.

HTH
B\rgds
100

"Wamiq Ansari" <wa***@msn.co m> wrote in message
news:uV******** ******@TK2MSFTN GP09.phx.gbl...
Hi!,
I am trying to add a value to a StringDictionar y using its Item Property

in
C#. However this throws an expection as follows:
Cannot implicitly convert type 'Component.Temp lateComponent' to 'string'.
The method I am using is as follows:

private StringDictionar y componentList = new StringDictionar y();

public void addComponent(Te mplateComponent docComponent)

{

componentList["AAA"] = docComponent;

}

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

Help!!!!

Wamiq


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9891
by: J.R | last post by:
I'm getting an error when I attempt to serialize a type StringDictionary, error suggests type not marked for Serialization, could someone tell me how to go about this? Thanks.
6
7491
by: John | last post by:
Hi! I have a StringDictionary itialized as follows: private void frmICUCalculations_Activated(object sender, System.EventArgs e) { StringDictionary dataDict = new StringDictionary(); dataDict.Add("Item1", "2001" ); dataDict.Add( "Item2", "2002" ); dataDict.Add( "Item3", "2003" ); }
4
3702
by: Sanjay Vyas | last post by:
Sorry, forgot to cross post this one.. This is rather unusual as we would expect any Collection class to implement ICollection interface and furthermore a Dictionary class should implement IDictionary interface. The StringDictionary class does implements all the methods of ICollection and IDictionary yet it does not list these interfaces....
8
1654
by: Joel Reinford | last post by:
I would like to build a class that has properties which can be accessed by string names or index numbers in the form of MyClass.Item("LastName"). The string names or item index values would be populated by a data-driven loop. I need a few pointers to get me started in the right direction. I'm pretty sure that I need a default Item property...
2
1318
by: rajmgopal | last post by:
Hi I am using a StringDictionary to store and pass a few string values retrieved from sql server database. I am using these values as inputs to several stored procedures After processing a few 100 or 1000 records , I get an error saying that one of the stored procedure parameter is expecting a value (which I assign from StringDictionary)...
0
1669
by: Simon Dahlbacka | last post by:
I was trying to use the built in settings management and added a User-scoped setting of type System.Collections.Specialized.StringDictionary I run my application, updated the Settings, did Settings.Default.Save() and when started the app again I noticed the new settings did not work! Looking in the created user.config, the...
3
8711
by: Bmack500 | last post by:
I have a sub, and a class. The sub is like this: Sub dothis() Dim aInfoListX As New infoWrapperClass aInfoListX.params = ReadConfig() Dim sqlCMD As New SqlCommand aInfoListX.sqlCmd = sqlCMD aInfoListX.sqlConn = New SqlClient.SqlConnection(aInfoListX.params.sqlserver) End Sub
0
1449
by: Hans | last post by:
Hello, I was trying to use the built in settings management and added a User-scoped setting of type System.Collections.Specialized.StringDictionary I run my application, updated the Settings, did Settings.Default.Save() and when started the app again I noticed the new settings did not work!
4
10669
by: Peter K | last post by:
Hi are there any benefits in using StringDictionary over Dictionary<string, string? It appears they achieve the same thing... (I could be wrong of course). thanks, Peter
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.