By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

IFormatProvider

P: n/a
Que
Hi

The I wrote the following Code

If Not txtInvoice.Text = "" Then

txtInvoice.Text =
Convert.ToInt32(txtInvoice.Text()).ToString("00000 0")

End If

txtInvoice is a TextBox

I use FxCop and it says I should rewrite the code with the following
resolution

"frmInvoiceDetail.txtInvoice_Leave(Object, EventArgs)
:Void makes a call to
System.Convert.ToInt32(System.String)
that does not explicitly provide an IFormatProvider.
This should be replaced with a call to
System.Convert.ToInt32(
System.String,System.IFormatProvider)."

What does it mean that I should Provide an IFormatProvider.

What is IFormatProvider

How does this work

Excuse me for my ignorance

Thanks in Advance

Regards
AQ

Sep 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Que,

This should be enough, I never know what character has to be for those
question marks.

Cint(txtInvoice.Text)ToString(????????)

Maybe you can try it yourself.

http://msdn.microsoft.com/library/de...lasstopic.aspI hope this helps,Cor"Que" <aq********@gmail.comschreef in berichtnews:11**********************@i3g2000cwc.go oglegroups.com...Hi>The I wrote the following Code> If Not txtInvoice.Text = "" Then> txtInvoice.Text =Convert.ToInt32(txtInvoice.Text()).ToString("0000 00")> End If>txtInvoice is a TextBox>I use FxCop and it says I should rewrite the code with the followingresolution>"frmInvoiceDetail.txtInvoice_L eave(Object, EventArgs) :Void makes a call toSystem.Convert.ToInt32(System.String) that does not explicitly provide an IFormatProvider. This should be replaced with a call toSystem.Convert.ToInt32( System.String,System.IFormatProvider).">What does it mean that I should Provide an IFormatProvider.>What is IFormatProvider>How does this work>Excuse me for my ignorance>Thanks in Advance>RegardsAQ>

Sep 18 '06 #2

P: n/a
Que
hi

thanks for the quick reply.
i do have that code,as you suggested
what i needed to know is how and why should IFormatProvider be
implimented and used

thanks again.
Que

Sep 18 '06 #3

P: n/a
An IFormatProvider provides culture specific information regarding how
dates, numbers etc are formatted (since different countries has different
rules). The Convert.ToInt32 method you are calling uses an IFormatProvider
that matches the settings you have in the regional settings in your control
panel. If you're getting input directly from the user this is most likely
the behaviour you want (I'm guessing that txtInvoice is a txtbox or
similar). If you need to transfer data between systems using different
country settings you need to use a common format for it so that each system
interprets it the same way (for example; 12.3 is not the same thing in
Sweden as it is in the US). That's when you specify a specific
IFormatProvider that uses the common rules that you need.

In your case it looks like FxCop is a bit overprotective. If you want to get
rid of the warning change your line to:
Convert.ToInt32(txtInvoice.Text,
CultureInfo.CurrentCulture).ToString("000000")
This is what the framework does for you internally anyway when you use the
version with only one parameter

/claes

"Que" <aq********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi

The I wrote the following Code

If Not txtInvoice.Text = "" Then

txtInvoice.Text =
Convert.ToInt32(txtInvoice.Text()).ToString("00000 0")

End If

txtInvoice is a TextBox

I use FxCop and it says I should rewrite the code with the following
resolution

"frmInvoiceDetail.txtInvoice_Leave(Object, EventArgs)
:Void makes a call to
System.Convert.ToInt32(System.String)
that does not explicitly provide an IFormatProvider.
This should be replaced with a call to
System.Convert.ToInt32(
System.String,System.IFormatProvider)."

What does it mean that I should Provide an IFormatProvider.

What is IFormatProvider

How does this work

Excuse me for my ignorance

Thanks in Advance

Regards
AQ

Sep 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.