ToString - 有意义的Vs.无用 [英] ToString - meaningful Vs. Useless

查看:48
本文介绍了ToString - 有意义的Vs.无用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




没有逐个案例,我怎么知道ToString方法返回有用的

信息,如Sytem.Int32,或无用的信息,如

System.Drawing.Bitmap(返回类的名称)。


Ron



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

推荐答案

您是否阅读过文档以了解给定方法调用可以返回的内容?

它通常是一个很好的指标,表明方法是否有用

你调用它的上下文。

-

问候


John Timney(MVP)

" Ron M. Newman" < co ********** @ confideltial.comwrote in message

news:eS ************** @ TK2MSFTNGP06.phx.gbl ...
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**********@confideltial.comwrote in message
news:eS**************@TK2MSFTNGP06.phx.gbl...

hi,


没有逐案,我怎么知道ToString?方法返回

有用的信息,比如Sytem.Int32,或无用的信息,比如

System.Drawing.Bitmap(返回类的名称)。


Ron


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



让我澄清一下。


let'采取字节的方式。例如,结构和位图结构。 class。


两者都有ToString。但是,在Bitmap中,这个方法只返回类

名称,这是没有意义和无用的,因为它没有覆盖

ToString。来自Object类。然而,Byte结构知道如何将
repersent本身作为字符串,因为它确实覆盖了ToString。方法。


我的问题:如何判断哪个类具有ToString?是有意义的,

,哪一个不是。这对我所做的序列化类型至关重要。我是否必须为每个可用对象设置开关/案例逻辑以手动决定

?或者是否有我可以使用的全包规则?


谢谢

Ron


" John Timney (MVP)" < x _ **** @ timney.eclipse.co.ukwrote in message

news:k9 ******************** @ eclipse .net.uk ...
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.ukwrote in message
news:k9********************@eclipse.net.uk...

您是否阅读过文档以了解给定的方法调用可以返回?b $ b返回?它通常是一个很好的指标,关于一个方法是否有用

在你调用它的上下文中。

-

问候


John Timney(MVP)


" Ron M. Newman" < co ********** @ confideltial.comwrote in message

news:eS ************** @ TK2MSFTNGP06.phx.gbl ...
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**********@confideltial.comwrote in message
news:eS**************@TK2MSFTNGP06.phx.gbl...

> hi,

没有逐案,我怎么知道ToString?方法返回有用的信息,如Sytem.Int32,或无用的信息,如
System.Drawing.Bitmap(返回类的名称)。

Ron
>

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




" Ron M. Newman"写道:
"Ron M. Newman" wrote:

没有逐案,我怎么知道ToString方法返回有用的

信息,如Sytem.Int32,或无用的信息,如

System.Drawing.Bitmap(返回类的名称)。
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).



在2.0中,如果它实现了IConvertible,你应该可以依赖于

ToString方法的可逆性。


在1.x中,我怀疑使用Parse(字符串)方法是一个非常好的

可靠指标。


超越如果它使用Object.ToString,那么结果将只是

类型名称。我认为任何类型的优点都是好的,因为任何类型的

覆盖ToString都会返回内容的格式化版本,

特别是对于值类型。


-


..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net

Delphi技能使.NET易于学习印刷,商店。

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.


这篇关于ToString - 有意义的Vs.无用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆