为什么String.ToString()? [英] Why String.ToString()?
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/2778827/c-why-does-the-string-type-have-a-tostring-method">C#:为什么字符串类型具有的ToString()方法
为什么会出现的ToString
方法存在于字符串
类(VB.NET)?
String.ToString()
会不会是一个开销如果使用像
TextBox.Text.ToString()
在的ToString
方法是在对象中找到
从字符串
继承。实施 Object.ToString
是打印的类型名称。
公共虚拟字符串的ToString(){
返回this.GetType()的ToString()。
}
类型字符串
覆盖此方法返回本身。
公共重写字符串的ToString(){
回到这一点;
}
在code TextBox.Text.ToString()
有的ToString
,但它不必要的电话是不太可能会有这样做任何noticable性能影响。
Possible Duplicate:
C#: why does the string type have a .ToString() method
Why is there a ToString
method exist in String
class (VB.NET)?
String.ToString()
Will it be a overhead if it is used like
TextBox.Text.ToString()
The ToString
method is found on Object
from which String
inherits. The implementation of Object.ToString
is to print the typename.
public virtual string ToString() {
return this.GetType().ToString();
}
The type String
overrides this method to return itself.
public override string ToString() {
return this;
}
The code TextBox.Text.ToString()
has an unnecessary call to ToString
, but it is unlikely that there will be any noticable performance impact from doing so.
这篇关于为什么String.ToString()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!