首页 新闻 会员 周边

关于字符串

0
悬赏园豆:5 [已解决问题] 解决于 2011-08-22 14:53
public override string ToString()
{
    return InternalFormat((RuntimeType) base.GetType(), this.GetValue());
}
  
private static string InternalFormat(RuntimeType eT, object value)
{
    if (eT.IsDefined(typeof(FlagsAttribute), false))
    {
        return InternalFlagsFormat(eT, value);
    }
    string name = GetName(eT, value);
    if (name == null)
    {
        return value.ToString();
    }
    return name;
}

ToString()大概了解了。那么

int i=1;
string aa=i+"";
string aa=i.ToString();

这两者的内核区别事那些呢?

梦怀天的主页 梦怀天 | 菜鸟二级 | 园豆:222
提问于:2011-08-22 10:41
< >
分享
最佳答案
0

string aa=i+""; 先对i执行ToString,然后进行字符串对象的拼接,生成一个新的字符串对象
 i.ToString(); 直接执行ToString函数

收获园豆:5
2012 | 高人七级 |园豆:21230 | 2011-08-22 12:40
也就是说2者效率上其实没什么区别咯
梦怀天 | 园豆:222 (菜鸟二级) | 2011-08-22 13:09
效率上i.ToString()更好一些,因为这个只要生成一次string对象,而 i+"" 需要两个string对象 【string对象是不可变的】
2012 | 园豆:21230 (高人七级) | 2011-08-23 07:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册