【发布时间】:2024-04-27 21:00:02
【问题描述】:
我注意到在 C# 中 + 运算符在左侧接受一个字符串,在右侧接受一个对象:
string output = "" + numbers.ElementAt(0);
//vs
string output = numbers.ElementAt(0).ToString();
为什么默认行为是接受右侧的对象而不是字符串?当我在其他 + 运算符中查找说 int 时,它是 int/int 而不是 int/object 的强类型。
我知道在 C# 中所有对象都有 ToString() 方法,这只是在上面的第一个示例中无需调用 .ToString() 的一种方法吗?
【问题讨论】:
标签: c# operator-keyword