【发布时间】:2020-08-02 01:14:15
【问题描述】:
例如下面的代码:
int n=1;
string str=$"{n}";
但是在显式添加ToString()之后,就不会发生装箱了。
int n=1;
//The compiler will recommend removing the explicit call of the ToString() method
string str=$"{n.ToString()}";
CLR via C#这本书写道String.Format会在内部调用ToString方法来获取对象的字符串表示形式。
既然内部调用了ToString方法,为什么会出现例1中的装箱呢?
【问题讨论】:
标签: c# string.format