gpt4 book ai didi

.net - 为什么 String.Format 是静态的?

转载 作者:行者123 更新时间:2023-12-03 07:28:49 24 4
gpt4 key购买 nike

比较

String.Format("Hello {0}", "World");

"Hello {0}".Format("World");

为什么 .Net 设计者选择静态方法而不是实例方法?你觉得怎么样?

最佳答案

Because the Format method has nothing to do with a string's current value.

对于所有字符串方法都是如此,因为 .NET 字符串是不可变的。

If it was non-static, you would need a string to begin with.

它的作用是:格式字符串。

我相信这只是 .NET 平台中许多设计缺陷的另一个例子(我并不是说这是火焰;我仍然发现 .NET 框架优于大多数其他框架)。

关于.net - 为什么 String.Format 是静态的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23228/

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