473,503 Members | 544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is KeyValuePair<string,string>.ToString intended as serialization building block?

KeyValuePair<string,stringhas a ToString method that returns the
KeyValue pair seperated by a comma and enclosed in [ ]:
[ name, Jane ]

Is this method used as a building block for serialization?

The reason I ask is because I dont see a "FromString" or "Parse"
static method that takes a string as an argument and returns a
KeyValuePair<string,stringobject.

also, the ToString resulting value does not look like it could be
parsed under all circumstances. If the value in the KeyValuePair
contains a comma the ToString method returns the value as is, without
enclosing it in quotes:

KeyValuePair<string,stringdemo
= new KeyValuePair<string,string>( "First, Names", "Billy,
Jane" ) ;
MessageBox.Show(demo.ToString());

resulting string: [First, Names, Billy, Jane]

-Steve

May 7 '07 #1
2 6505
On May 7, 3:59 pm, Steve Richter <StephenRich...@gmail.comwrote:
KeyValuePair<string,stringhas a ToString method that returns the
KeyValue pair seperated by a comma and enclosed in [ ]:
[ name, Jane ]

Is this method used as a building block for serialization?

The reason I ask is because I dont see a "FromString" or "Parse"
static method that takes a string as an argument and returns a
KeyValuePair<string,stringobject.

also, the ToString resulting value does not look like it could be
parsed under all circumstances. If the value in the KeyValuePair
contains a comma the ToString method returns the value as is, without
enclosing it in quotes:

KeyValuePair<string,stringdemo
= new KeyValuePair<string,string>( "First, Names", "Billy,
Jane" ) ;
MessageBox.Show(demo.ToString());

resulting string: [First, Names, Billy, Jane]

-Steve
No, its not. Its simply there to get a string version of the
instance. All .Net objects have a ToString method; most simply use
the default implementation to return the type name, but key value
pair, overrides to call ToString on both the key object and value
object (which in your case are both strings).

Serialization would be done by decorating a class with the
SerializationAttribute.

May 7 '07 #2
Steve,

The ToString method is not meant to be used for Serialization. The
ToString method is located on the Object class, and is not intended to be
used for serialization. Rather, its intention is to return a human-readable
string that is culture-sensitive (from the documentation).

This is why you do not see a FromString method.

Generally, I would use the TypeConverter class (rather, a class derived
from that) to perform the conversion. However, it would be up to the
KeyValuePair<TKey, TValueinstance to indicate what the TypeConverter
should be, which it does not.

Is there something specific you are trying to do? The structure is
serializable (assuming that TKey and TValue are serializable) but that would
allow you to serialize the instance to a binary stream, or a xml message.
You can also try XML serialization as well.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steve Richter" <St************@gmail.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
KeyValuePair<string,stringhas a ToString method that returns the
KeyValue pair seperated by a comma and enclosed in [ ]:
[ name, Jane ]

Is this method used as a building block for serialization?

The reason I ask is because I dont see a "FromString" or "Parse"
static method that takes a string as an argument and returns a
KeyValuePair<string,stringobject.

also, the ToString resulting value does not look like it could be
parsed under all circumstances. If the value in the KeyValuePair
contains a comma the ToString method returns the value as is, without
enclosing it in quotes:

KeyValuePair<string,stringdemo
= new KeyValuePair<string,string>( "First, Names", "Billy,
Jane" ) ;
MessageBox.Show(demo.ToString());

resulting string: [First, Names, Billy, Jane]

-Steve

May 7 '07 #3

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

Similar topics

7
25629
by: Russell Hind | last post by:
I want to create an array of key value pairs. This code compiles fine: KeyValuePair<string, object> kvps = { new KeyValuePair<string,object>( "int", 5 ), new KeyValuePair<string,object>(...
44
39125
by: Zytan | last post by:
The docs for List say "The List class is the generic equivalent of the ArrayList class." Since List<is strongly typed, and ArrayList has no type (is that called weakly typed?), I would assume...
2
5856
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the...
0
7203
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,...
0
7087
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...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7334
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...
1
5014
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...
0
3168
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...
0
1514
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 ...
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
383
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...

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.