Format(string, object)
Format(string, object, object)
Format(string, object, object, object)
Format(string, params object[])
doesn't the last one cover the first three?
in the last case u need to iterate throught the list of objects. This can
be a little annoying
JV> Why does String.Format have overrides of:
JV>
JV> Format(string, object)
JV> Format(string, object, object)
JV> Format(string, object, object, object)
JV> Format(string, params object[])
JV> doesn't the last one cover the first three?
JV>
---
WBR, Michael Nemtsev [C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
The first three are used for performace reason. To call the fourth one
the code has to create an Array object to handle the properties.
--
Göran Andersson
_____
http://www.guffa.com
Do you mean that Format has to iterate through the objects? If so, it has
to anyway because the first three just create an array and pass it to the
fourth one.
That was my first thought but, the implementation of the first three creates
an array of the object parameters and passes it to the params override.
"John Vottero" <JVot...@mvpsi.com> wrote in message
news:u7SfFRgU...@TK2MSFTNGP05.phx.gbl...
So it may not be performance but just making it easier to you. If not you
would need to create the array outside the method.
--
Ignacio Machin
machin AT laceupsolutions com
Not all languages are guaranteed to have C#'s handling of "params"
parameters - in other words, in some languages you may have to
explicitly create the array. That would hurt readability. By having a
few overloads which don't require an array at all, all language can
have easy-to-read calls for simple cases.
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Ok, then in this case it's for the simplicity of the call, so that the
creation of the array is done in the background.
I know that String.Concat has overrides in the same manner, and they
have implementations that are optimised for performance. I guess that
formatting is so expensive anyway, that optimising the calling doesn't
really make sense.
"Göran Andersson" <gu...@guffa.com> wrote in message
news:%233QAhCj...@TK2MSFTNGP03.phx.gbl...
When you're using a language which doesn't support it? There are
languages targeting .NET other than C# and VB.NET, you know.
What I meant is that the creation of the array is done in the framework
code, not in the application code.