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