473,545 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ToString - meaningful Vs. Useless

hi,

without going case-by-case, how do I know a "ToString" method returns useful
information, like for Sytem.Int32, or useless information like for
System.Drawing. Bitmap (returning the name of the class).

Ron
Aug 24 '06 #1
12 1184
Have you read the documentation to see what a given method call can return?
Its usually a good indicator as to whether a method will be useful or not in
the context in which you call it.
--
Regards

John Timney (MVP)
"Ron M. Newman" <co**********@c onfideltial.com wrote in message
news:eS******** ******@TK2MSFTN GP06.phx.gbl...
hi,

without going case-by-case, how do I know a "ToString" method returns
useful information, like for Sytem.Int32, or useless information like for
System.Drawing. Bitmap (returning the name of the class).

Ron

Aug 24 '06 #2
Let me clarify.

let's take the "Byte" structure for instance, and the "Bitmap" class.

Both have ToString. However, in Bitmap this method only returns the class
name, which is meaningless and useless because it doesn't override the
"ToString" from the Object class. The Byte structure however knows how to
repersent itself as string becusae it does override the "ToString" method.

My quetion: How do I tell which class that has a "ToString" is meaningful,
and which one isn't. this is essential to the type of serialization I'm
doing. do I have to put switch/case logic for every available object to make
the decision manually? or is there an all-inclusive rule I can use?

thanks
Ron

"John Timney (MVP)" <x_****@timney. eclipse.co.ukwr ote in message
news:k9******** ************@ec lipse.net.uk...
Have you read the documentation to see what a given method call can
return? Its usually a good indicator as to whether a method will be useful
or not in the context in which you call it.
--
Regards

John Timney (MVP)
"Ron M. Newman" <co**********@c onfideltial.com wrote in message
news:eS******** ******@TK2MSFTN GP06.phx.gbl...
>hi,

without going case-by-case, how do I know a "ToString" method returns
useful information, like for Sytem.Int32, or useless information like for
System.Drawing .Bitmap (returning the name of the class).

Ron


Aug 24 '06 #3
"Ron M. Newman" wrote:
without going case-by-case, how do I know a "ToString" method returns useful
information, like for Sytem.Int32, or useless information like for
System.Drawing. Bitmap (returning the name of the class).
In 2.0, if it implements IConvertible, you should be able to rely on
the reversibility of the ToString method.

In 1.x, I suspect that having a Parse(string) method is a pretty
reliable indicator.

Beyond that, if it uses Object.ToString , then the result will just be
the type name. I'd imagine the odds are good that any type that
overrides ToString is returning a formatted version of the content,
especially for value types.

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 24 '06 #4
Hi,

Thanks. Eventually I did just that, I'm checking for a local ToString
implementation that's indigenous to the type and not derived from
elsewhere - this is a good indication for me that the output would be
meaningful.

Thanks for understanding what I was looking for :-)

Ron

"Jon Shemitz" <jo*@midnightbe ach.comwrote in message
news:44******** ******@midnight beach.com...
"Ron M. Newman" wrote:
>without going case-by-case, how do I know a "ToString" method returns
useful
information, like for Sytem.Int32, or useless information like for
System.Drawing .Bitmap (returning the name of the class).

In 2.0, if it implements IConvertible, you should be able to rely on
the reversibility of the ToString method.

In 1.x, I suspect that having a Parse(string) method is a pretty
reliable indicator.

Beyond that, if it uses Object.ToString , then the result will just be
the type name. I'd imagine the odds are good that any type that
overrides ToString is returning a formatted version of the content,
especially for value types.

--

.NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.

Aug 25 '06 #5
Your question is not clear. What do you mean by "meaningles s?" When the
ToString method is overridden in a class, the developer that overrides it
decides what the implementation should produce. I'm sure that this is for
the purpose of creating something "meaningful " out of the method, but what
the "meaning" is depends upon the class and the implementation of the
override. In other words, things are meaningful to different people at
different times for different reasons.

In fact, most overrides of the ToString method are meaningful only to
developers. They provide quick information about a class during the
debugging process. However, other overrides are useful for other purposes,
such as the override of ToString on Enums that displays the token of the
enumerated value.

I do not know of any way to tell whether or not a method is overridden in an
inherited class. It is probably possible to do this by using Reflection,
perhaps by getting a MethodInfo from both the base and derived class and
comparing them. But still, you aren't going to know whether the ToString
method implementation is "meaningful " to you. In fact, you haven't even
*defined* "meaningful ."

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
"Ron M. Newman" <co**********@c onfideltial.com wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Let me clarify.

let's take the "Byte" structure for instance, and the "Bitmap" class.

Both have ToString. However, in Bitmap this method only returns the class
name, which is meaningless and useless because it doesn't override the
"ToString" from the Object class. The Byte structure however knows how to
repersent itself as string becusae it does override the "ToString" method.

My quetion: How do I tell which class that has a "ToString" is meaningful,
and which one isn't. this is essential to the type of serialization I'm
doing. do I have to put switch/case logic for every available object to
make the decision manually? or is there an all-inclusive rule I can use?

thanks
Ron

"John Timney (MVP)" <x_****@timney. eclipse.co.ukwr ote in message
news:k9******** ************@ec lipse.net.uk...
>Have you read the documentation to see what a given method call can
return? Its usually a good indicator as to whether a method will be
useful or not in the context in which you call it.
--
Regards

John Timney (MVP)
"Ron M. Newman" <co**********@c onfideltial.com wrote in message
news:eS******* *******@TK2MSFT NGP06.phx.gbl.. .
>>hi,

without going case-by-case, how do I know a "ToString" method returns
useful information, like for Sytem.Int32, or useless information like
for System.Drawing. Bitmap (returning the name of the class).

Ron



Aug 25 '06 #6
Kevin Spencer wrote:
I do not know of any way to tell whether or not a method is overridden in an
inherited class. It is probably possible to do this by using Reflection,
perhaps by getting a MethodInfo from both the base and derived class and
comparing them.
Just get the MethodInfo and look at the DeclaringType property.

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 25 '06 #7
Thanks Jon. I'll file that tidbit away!

--

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
"Jon Shemitz" <jo*@midnightbe ach.comwrote in message
news:44******** *******@midnigh tbeach.com...
Kevin Spencer wrote:
>I do not know of any way to tell whether or not a method is overridden in
an
inherited class. It is probably possible to do this by using Reflection,
perhaps by getting a MethodInfo from both the base and derived class and
comparing them.

Just get the MethodInfo and look at the DeclaringType property.

--

.NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.

Aug 25 '06 #8
I'll join you in filing that, cos thats a useful snippet to know!!

Regards

John Timney (MVP)
"Kevin Spencer" <uc*@ftc.govwro te in message
news:ep******** *****@TK2MSFTNG P02.phx.gbl...
Thanks Jon. I'll file that tidbit away!

--

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
"Jon Shemitz" <jo*@midnightbe ach.comwrote in message
news:44******** *******@midnigh tbeach.com...
>Kevin Spencer wrote:
>>I do not know of any way to tell whether or not a method is overridden
in an
inherited class. It is probably possible to do this by using Reflection,
perhaps by getting a MethodInfo from both the base and derived class and
comparing them.

Just get the MethodInfo and look at the DeclaringType property.

--

.NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.


Aug 25 '06 #9

Kevin Spencer wrote:
In fact, most overrides of the ToString method are meaningful only to
developers. They provide quick information about a class during the
debugging process. However, other overrides are useful for other purposes,
such as the override of ToString on Enums that displays the token of the
enumerated value.
I believe I read somewhere that the framework designers only intended
the ToString method to be used for debugging. So what you said makes
sense.

Brian

Aug 26 '06 #10

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

Similar topics

1
6324
by: pyguy2 | last post by:
Issues of socket programming can be wierd, so I'm looking for some comments. In my python books I find exclusive use of socket.close(). From my other readings, I know about a "partial close operation". So, I figured it would be useful to post some code about how socket.close() has an implicit send in it and you can actually gain some...
205
10468
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
3
2049
by: windandwaves | last post by:
Hi, I am trying to make errors a bit more meaningful for my users. I am trying to fix error 3201 where there is a missing field in a form. If I do not do any error trapping, then I get You cannot add or change a record because a related record is required in table 'my table name'.
3
4078
by: Fredrik Wahlgren | last post by:
Hi I found an interesting piece of code which shows how to makee an Excel automation add-in at http://www.codeproject.com/dotnet/excelnetauto.asp. I decide to experiment with it and i made a few changes. I now have a method that takes an Excel.Range as a parameter. My problem now is that when I use Excel's function wizard, there are thre...
26
2695
by: Michi Henning | last post by:
I've been having problem with destructors in the context of having ported C# code developed under .NET to Mono. What happens is that, on a dual-CPU machine, various parts of the code crash randomly (and rarely). This always happens during process shutdown, after some thread has called System.Environment.Exit(). Clearly, some sort of race...
11
1698
by: Rickie | last post by:
Dear fellow software engineers, Is the web menu in asp 2.0 essentielle a useless control ? How many people( including msdn itself) are using server menu controls? Its a menu which always postback to server, which cant be caught on the event of a menuitem. Wouldnt we rather use other ways of making menus which are essentially clientsite ?...
2
4350
by: Srini | last post by:
Hi, Can anyone please tell me how to retrieve meaningful value from registry value in REG_Binary type? I tried to convert REG_Binary value to string using the following code.
9
1365
by: Lars Eighner | last post by:
In the code below, the line "unsigned int ktop,kbot;" seems to be useless as ktop and kbot are never used. Yet, this work with it and breaks without it. Any idea why? #include <stdio.h>
38
1775
by: tshad | last post by:
In VS 2008, why doesn't ToString require "()". If I have Option Strict On on why can I do both: selectedIndex.ToString() selectedIndex.ToString or sQuery = temp.ToUpper().IndexOf("friend")
0
7457
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
7391
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
7802
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
7410
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...
0
5962
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...
1
5320
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
4941
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...
0
3443
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...
1
1869
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

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.