在我遇到的大多数代码中,他们在使用String.Format()时显式地将int或其他数字转换为字符串,尽管从我注意到它没有必要.是否有一些我缺少的东西需要在将数字用作字符串之前将数字显式转换为字符串?
明确:
int i = 13;
string example = String.Format("If a Friday lands on the {0}th of the month, it is generally considered to be an unlucky day!",
i.ToString());
Run Code Online (Sandbox Code Playgroud)
产生example如下:"If a Friday lands on the 13th of the month, it is generally considered to be an unlucky day!"
不明确的:
int i = 13;
string example = String.Format("If a Friday lands on the {0}th of the month, it is generally considered to be an unlucky day!",
i);
Run Code Online (Sandbox Code Playgroud)
产生example为:( "If a Friday lands on the 13th of the month, it is generally considered to be an unlucky day!"与显式转换相同).那么为什么我看到的大多数编码器会这样做呢?