Is there any sane reason why the function String.Format in .net (for C# and VB.net at least) shared and not like .split, .substring or whatever a normal function.
What would be bad about
Dim a as String = "1+2={0}".format(1+2) (would be good)
vs.
Dim a as String = String.Format("1+2={0}",1+2) (the way it works)
It always bugs me when using this function – which i do quite often.
Thx.
Maybe Eric Lippert still has the design notes on that but apart from that I don’t think this can be accurately answered.
Still, as a workaround, if you desperately need this, then you can write an extension method:
My guess is that most string methods actually operate on the string, transforming it in a straightforward and foreseeable manner, such as
Substring,ReplaceandPadLeft. WithFormatthe core string is just a pattern that is applied to integrate the operands into. Conceptually most instance methods onstringcan be seen as manipulating astring(I know, this isn’t what happens, I’m just painting a picture here), while the static methods just work with it.As noted, just a guess. In the end it probably was just a decision and the reason was lost in time.