473,698 Members | 2,737 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 4118
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
9899
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
7504
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
3706
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. Am I missing something here or was it an oversight on the part of the class developer. Maybe I have...
8
1664
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 but I'm not sure how to create that or index the other properties. A short code example is below ...
2
1325
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) but not receiving the same I have not been able to resolve the issue.
0
1676
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 StringDictionary was serialized to the immensely useful <value />
3
8724
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
1453
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
10678
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
8683
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
6528
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.