473,657 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is KeyValuePair<st ring,string>.To String intended as serialization building block?

KeyValuePair<st ring,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<st ring,stringobje ct.

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<st ring,stringdemo
= new KeyValuePair<st ring,string>( "First, Names", "Billy,
Jane" ) ;
MessageBox.Show (demo.ToString( ));

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

-Steve

May 7 '07 #1
2 6522
On May 7, 3:59 pm, Steve Richter <StephenRich... @gmail.comwrote :
KeyValuePair<st ring,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<st ring,stringobje ct.

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<st ring,stringdemo
= new KeyValuePair<st ring,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
SerializationAt tribute.

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<TK ey, 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.co m

"Steve Richter" <St************ @gmail.comwrote in message
news:11******** *************@o 5g2000hsb.googl egroups.com...
KeyValuePair<st ring,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<st ring,stringobje ct.

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<st ring,stringdemo
= new KeyValuePair<st ring,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
25674
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>( "string", "robot") }; But is their no shorthand to this such as KeyValuePair<string,object> kvps = {{"int",5 },{"string","a string"}};
44
39153
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 List<is far better. So, why do people use ArrayList so often? Am I missing somehing? What's the difference between them? Zytan
2
5883
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 dictionary essentially creates the following array: Key Value
0
8411
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
8323
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,...
0
8739
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
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
1969
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.