在我遇到的大多数代码中,他们在使用 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());
产生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);
产生example
为:("If a Friday lands on the 13th of the month, it is generally considered to be an unlucky day!"
与显式转换相同)。那么为什么我看到的大多数程序员都这样做呢?