Why do the overloads of String.Format exist?

后端 未结 2 784
逝去的感伤
逝去的感伤 2021-01-07 20:25

I was using Reflector to look at the implementation of String.Format and had always been under the impression that the overloads of String.Format that took 1, 2 & 3 argu

2条回答
  •  清酒与你
    2021-01-07 21:25

    One reason, as Hans mentions, is that creating an array is a lot of unnecessary overhead in most common cases of formatting a string. This saves space in the EXE.

    Another reason is that not all languages support variadic functions (use of params in C#). This allows users of those languages to avoid array creation for the most common cases of string formatting. This saves a lot for languages that don't have simple syntax for array creation and initialization.

提交回复
热议问题