gpt4 book ai didi

c# - C# 中的 String.Format 和 Composite String 有什么区别?

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:41 30 4
gpt4 key购买 nike

这两种语法有什么区别?

是否存在必须使用 String.Format 而不是复合字符串的情况?

Console.WriteLine("{0:d} {0:t}",DateTime.Now);
Console.WriteLine(String.Format("{0:d} {0:t}",DateTime.Now));

最佳答案

它们之间没有任何区别,因为

Console.WriteLine("{0:d} {0:t}",DateTime.Now);

将通过此重载函数调用 String.Format 函数。

public virtual void WriteLine(String format, Object arg0)
{
WriteLine(String.Format(FormatProvider, format, arg0));
}

console.WriteLine源代码

关于c# - C# 中的 String.Format 和 Composite String 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52345207/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com