473,378 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

string Format overrides

Why does String.Format have overrides of:

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?

Feb 16 '07 #1
10 2587
Hello John,

in the last case u need to iterate throught the list of objects. This can
be a little annoying

JVWhy does String.Format have overrides of:
JV>
JVFormat(string, object)
JVFormat(string, object, object)
JVFormat(string, object, object, object)
JVFormat(string, params object[])
JVdoesn'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
Feb 16 '07 #2
John Vottero wrote:
Why does String.Format have overrides of:

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?
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
Feb 16 '07 #3
"Michael Nemtsev" <ne*****@msn.comwrote in message
news:a2***************************@msnews.microsof t.com...
Hello John,

in the last case u need to iterate throught the list of objects. This can
be a little annoying
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.
>
JVWhy does String.Format have overrides of:
JVJVFormat(string, object)
JVFormat(string, object, object)
JVFormat(string, object, object, object)
JVFormat(string, params object[])
JVdoesn'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


Feb 16 '07 #4
"Göran Andersson" <gu***@guffa.comwrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
John Vottero wrote:
>Why does String.Format have overrides of:

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?

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.
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.
Feb 16 '07 #5
Hi,

"John Vottero" <JV******@mvpsi.comwrote in message
news:u7**************@TK2MSFTNGP05.phx.gbl...
"Göran Andersson" <gu***@guffa.comwrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
>John Vottero wrote:
>>Why does String.Format have overrides of:

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?

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.

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.
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
Feb 16 '07 #6
John Vottero <JV******@mvpsi.comwrote:
Why does String.Format have overrides of:

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?
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
Feb 16 '07 #7
John Vottero wrote:
"Göran Andersson" <gu***@guffa.comwrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
>John Vottero wrote:
>>Why does String.Format have overrides of:

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?
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.

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.
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
_____
http://www.guffa.com
Feb 17 '07 #8
what are you and ignacio talking about ?
under what circumstances do you ever have to explicitely create an array to
call any string.Format(string, params object[])) ??? when is the params
array ever NOT done in the background ?

"Göran Andersson" <gu***@guffa.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
John Vottero wrote:
>"Göran Andersson" <gu***@guffa.comwrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
>>John Vottero wrote:
Why does String.Format have overrides of:

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?

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.

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.

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
_____
http://www.guffa.com

Feb 17 '07 #9
gerry <ge**@canada.comwrote:
what are you and ignacio talking about ?
under what circumstances do you ever have to explicitely create an array to
call any string.Format(string, params object[])) ??? when is the params
array ever NOT done in the background ?
When you're using a language which doesn't support it? There are
languages targeting .NET other than C# and VB.NET, you know.

--
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
Feb 17 '07 #10
Yes, you are right, I was a bit unclear on that one.

What I meant is that the creation of the array is done in the framework
code, not in the application code.

gerry wrote:
what are you and ignacio talking about ?
under what circumstances do you ever have to explicitely create an array to
call any string.Format(string, params object[])) ??? when is the params
array ever NOT done in the background ?

"Göran Andersson" <gu***@guffa.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>John Vottero wrote:
>>"Göran Andersson" <gu***@guffa.comwrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
John Vottero wrote:
Why does String.Format have overrides of:
>
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?
>
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.

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.
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
_____
http://www.guffa.com


--
Göran Andersson
_____
http://www.guffa.com
Feb 17 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: Tubs | last post by:
Am i missing something or does the .Net Framework have a quirk in the way methods work on an object. In C++ MFC, if i have a CString and i use the format method, i format the string i am using. ...
5
by: Mart | last post by:
Hi everybody, I plan to have a LOT of SQL string in my app. So I need your advice for this. Is it a good idea to store all my SQL string in the app.config file? For a maintenance point of...
5
by: jan axelson | last post by:
My application is using RegisterDeviceNotification() to detect attachment and removal of a USB HID-class device. The form is receiving WM_DEVICECHANGE messages with wParam set to...
1
by: Jeremy | last post by:
I am displaying a boolean field in a grid & want to format it Yes/No. Can someone tell me what the formatstring for this is? That is, DataGridTextBoxColumn.Format = ?? Jeremy
3
by: Philip Wagenaar | last post by:
I created a Mustinherit class with two must override readonly properties: Public MustInherit Class RequestPart Public MustOverride ReadOnly Property Description() As Boolean Public MustOverride...
1
by: Steve Long | last post by:
Hello, I'm trying to expose a string dictionary to a COM client (VB6) and I'm having some trouble with the Keys property of the StringDictionary. My class is laid out as such: The problem is that...
2
by: mac | last post by:
Assume you have a textbox named "displayValue" What is the difference (if any) between these two approaches: 1.) float var; var = 0.42F; displayValue.Text = var.ToString 2.)
4
by: Trapulo | last post by:
I've a webservice with a string parameter. I call this webservice passing a string that is 1129 chars length. On the webservice, the received string is 1146 length (I tested sizes with...
1
by: Allan Ebdrup | last post by:
I get the error: "Cannot create an object of type 'CustomWizard' from its string representation 'CustomWizard1' for the CustomWizard Property." when I view my custom server web control in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.