String.Format

S

san

Hello, all! I have question about String.Format method.

There are two variants: public static string Format(string, params
object[]); and public static string Format(IFormatProvider, string, params
object[]);

What happens if i will use String.Format("{0} and {1}", "one", "two")
instead of String.Format(System.Globalization.CultureInfo.CurrentCulture,
"{0} and {1}", "one", "two")?

What differense between these two methods?

Then i use FxCop i have a lot of errors with this resolution: "The call to
'String.Format(String format, Object arg0)' does not explicitly provide
IFormatProvider. This should be replaced with a call to an overload that
does: String.Format(IFormatProvider provider, String format, Object[] args)"

Is this really Critical?

Thanks alot, Alex.
 
O

Oliver Sturm

san said:
There are two variants: public static string Format(string, params
object[]); and public static string Format(IFormatProvider, string, params
object[]);

What happens if i will use String.Format("{0} and {1}", "one", "two")
instead of String.Format(System.Globalization.CultureInfo.CurrentCulture,
"{0} and {1}", "one", "two")?

What differense between these two methods?

None :)
Then i use FxCop i have a lot of errors with this resolution: "The call to
'String.Format(String format, Object arg0)' does not explicitly provide
IFormatProvider. This should be replaced with a call to an overload that
does: String.Format(IFormatProvider provider, String format, Object[] args)"

Is this really Critical?

It may not be critical, but it's nevertheless an important thing to
understand. I have searched Google and found an article for you that
explains things quite nicely:

http://www.boyet.com/Articles/SpecifyIFormatProvider.html



Oliver Sturm
 
G

Guest

Hi,

The IFormatProvider should be used when your application uses globalization
and different cultures.

In FXCop, you can disable this rule, so that it does not give any error if
you are not providing this parameter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top