Showing posts with label framework. Show all posts
Showing posts with label framework. Show all posts

Monday, March 26, 2012

string.ToString (IFormatProvider) doesnt take case of the provider ?

It's seem like a bug in the framework... but I'm not sure...
It's must seems weird, but I have a string variable and I want to apply a format and get the string formatted in that format. My original string is a numeric value and I want to obtain a string formatted based on the culture of the current thread.
string numericValue = "1234.56";
string returnValue = numericValue.ToString (System.Globalization.NumberFormatInfo.CurrentInfo);
But, it doesn't work. So, I check the code in the framework and there two methods ToString on the string Object. And both, return the this even the one with the provider parameter.

publicstringToString(IFormatProvider provider){returnthis;}
I you agree with me that there is a bug in the framework ?

hello.
i think that you're seeing it the wrong way.
what you want to do is get your number (ex.: double) and use the ToString method of that struct.
Double num = ...;
num.ToString( provider );
i think that using tostring with a provider on a string doesn't make any sense...

What I am trying to do is converting the format of a string from one culture to another. Say that you have a string 1 234,56 on the french-Canada culture and want to format the string to the english-US culture. I can parse the string to double and returning back to string. But I see that the string class have a method ToString who take a FormatProvider and do nothing with the parameter.


hello.

what i was trying to say is that if you're supposed to have a number, then use a variable of the desired type to keep it and parse it to the desired culture.


My simple solution is:
private void Form1_Load(object sender, EventArgs e)
{
double i = 1234.56;
textBox1.Text = i.ToString("0,000.00");

}

Saturday, March 24, 2012

StringWriter object and dispose method

Re hello,
I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to export
in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :
example :
Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing
BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
As Boolean)' is not accessible in that context. it is protected..
I can use the Close() method but i m not sure that this last one have the
same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object
Thanks for you help
fabriceUse Close(). Setting the objec to null stops the object from being
referenced, so the GC will clear it out when it's ready. Note that Dispose
DOES not remove the object from memory.
http://msdn.microsoft.com/msdnmag/issues/1100/gci/
"fabrice" <emouchet@.test.com> wrote in message
news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...
> Re hello,
> I m' sorry for my questions ..
> Under framework 1.1 with vb.net, i m using a StringWriter object to export
> in .xls file.
> To empty memory, I would like to use the propterty dispose on the object
> StringWriter.
> But i have received an error like this :
> example :
> Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
> ...
> myStringWriter.Dispose(System.Boolean)(true)
> myStringWriter=Nothing
>
> BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
> As Boolean)' is not accessible in that context. it is protected..
>
> I can use the Close() method but i m not sure that this last one have the
> same effects for Garbage Collector ?
> Is it possible to use Dispose method with StringWriter object
>
> Thanks for you help
> fabrice
>
Great.
Thanks for you help.
have a nice day
"Dan Bass" <na> a crit dans le message de news:
%23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...
> Use Close(). Setting the objec to null stops the object from being
> referenced, so the GC will clear it out when it's ready. Note that Dispose
> DOES not remove the object from memory.
> http://msdn.microsoft.com/msdnmag/issues/1100/gci/
>
> "fabrice" <emouchet@.test.com> wrote in message
> news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...
>
remember that you also don't need <myObject> = Nothing explicitly in order
for the GC to clean the object up, although it is (IMO) good coding
practice.
"fabrice" <emouchet@.test.com> wrote in message
news:ewVgTr$BHHA.4928@.TK2MSFTNGP02.phx.gbl...
> Great.
> Thanks for you help.
> have a nice day
> "Dan Bass" <na> a crit dans le message de news:
> %23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...
>
Thanks Dan.
"Dan Bass" <na> a crit dans le message de news:
OgD8SCACHHA.3380@.TK2MSFTNGP04.phx.gbl...
> remember that you also don't need <myObject> = Nothing explicitly in order
> for the GC to clean the object up, although it is (IMO) good coding
> practice.
> "fabrice" <emouchet@.test.com> wrote in message
> news:ewVgTr$BHHA.4928@.TK2MSFTNGP02.phx.gbl...
>

StringWriter object and dispose method

Re hello,

I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to export
in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :

example :

Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing

Quote:

Originally Posted by

Quote:

Originally Posted by

>Error


BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
As Boolean)' is not accessible in that context. it is protected..

I can use the Close() method but i m not sure that this last one have the
same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object

Thanks for you help
fabriceUse Close(). Setting the objec to null stops the object from being
referenced, so the GC will clear it out when it's ready. Note that Dispose
DOES not remove the object from memory.

http://msdn.microsoft.com/msdnmag/issues/1100/gci/
"fabrice" <emouchet@.test.comwrote in message
news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Re hello,
>
I m' sorry for my questions ..
Under framework 1.1 with vb.net, i m using a StringWriter object to export
in .xls file.
To empty memory, I would like to use the propterty dispose on the object
StringWriter.
But i have received an error like this :
>
example :
>
Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
...
myStringWriter.Dispose(System.Boolean)(true)
myStringWriter=Nothing
>

Quote:

Originally Posted by

Quote:

Originally Posted by

>>Error


>
BC30390: 'System.IO.StringWriter.Protected Overrides Sub Dispose(disposing
As Boolean)' is not accessible in that context. it is protected..
>
>
I can use the Close() method but i m not sure that this last one have the
same effects for Garbage Collector ?
Is it possible to use Dispose method with StringWriter object
>
>
Thanks for you help
fabrice
>


Great.
Thanks for you help.
have a nice day

"Dan Bass" <naa crit dans le message de news:
%23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>
Use Close(). Setting the objec to null stops the object from being
referenced, so the GC will clear it out when it's ready. Note that Dispose
DOES not remove the object from memory.
>
http://msdn.microsoft.com/msdnmag/issues/1100/gci/
>
>
>
"fabrice" <emouchet@.test.comwrote in message
news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>Re hello,
>>
>I m' sorry for my questions ..
>Under framework 1.1 with vb.net, i m using a StringWriter object to
>export in .xls file.
>To empty memory, I would like to use the propterty dispose on the object
>StringWriter.
>But i have received an error like this :
>>
>example :
>>
>Dim myStringWriter As System.IO.StringWriter = New System.IO.StringWriter
>...
>myStringWriter.Dispose(System.Boolean)(true)
>myStringWriter=Nothing
>>

Quote:

Originally Posted by

>>>Error


>>
>BC30390: 'System.IO.StringWriter.Protected Overrides Sub
>Dispose(disposing As Boolean)' is not accessible in that context. it is
>protected..
>>
>>
>I can use the Close() method but i m not sure that this last one have the
>same effects for Garbage Collector ?
>Is it possible to use Dispose method with StringWriter object
>>
>>
>Thanks for you help
>fabrice
>>


>
>


remember that you also don't need <myObject= Nothing explicitly in order
for the GC to clean the object up, although it is (IMO) good coding
practice.

"fabrice" <emouchet@.test.comwrote in message
news:ewVgTr$BHHA.4928@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Great.
Thanks for you help.
have a nice day
>
"Dan Bass" <naa crit dans le message de news:
%23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>>
>Use Close(). Setting the objec to null stops the object from being
>referenced, so the GC will clear it out when it's ready. Note that
>Dispose DOES not remove the object from memory.
>>
>http://msdn.microsoft.com/msdnmag/issues/1100/gci/
>>
>>
>>
>"fabrice" <emouchet@.test.comwrote in message
>news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>>Re hello,
>>>
>>I m' sorry for my questions ..
>>Under framework 1.1 with vb.net, i m using a StringWriter object to
>>export in .xls file.
>>To empty memory, I would like to use the propterty dispose on the object
>>StringWriter.
>>But i have received an error like this :
>>>
>>example :
>>>
>>Dim myStringWriter As System.IO.StringWriter = New
>>System.IO.StringWriter
>>...
>>myStringWriter.Dispose(System.Boolean)(true)
>>myStringWriter=Nothing
>>>
>>>>Error
>>>
>>BC30390: 'System.IO.StringWriter.Protected Overrides Sub
>>Dispose(disposing As Boolean)' is not accessible in that context. it is
>>protected..
>>>
>>>
>>I can use the Close() method but i m not sure that this last one have
>>the same effects for Garbage Collector ?
>>Is it possible to use Dispose method with StringWriter object
>>>
>>>
>>Thanks for you help
>>fabrice
>>>


>>
>>


>
>


Thanks Dan.

"Dan Bass" <naa crit dans le message de news:
OgD8SCACHHA.3380@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

remember that you also don't need <myObject= Nothing explicitly in order
for the GC to clean the object up, although it is (IMO) good coding
practice.
>
"fabrice" <emouchet@.test.comwrote in message
news:ewVgTr$BHHA.4928@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>Great.
>Thanks for you help.
>have a nice day
>>
>"Dan Bass" <naa crit dans le message de news:
>%23mDFZP$BHHA.3540@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>>>
>>Use Close(). Setting the objec to null stops the object from being
>>referenced, so the GC will clear it out when it's ready. Note that
>>Dispose DOES not remove the object from memory.
>>>
>>http://msdn.microsoft.com/msdnmag/issues/1100/gci/
>>>
>>>
>>>
>>"fabrice" <emouchet@.test.comwrote in message
>>news:Os20oF$BHHA.4472@.TK2MSFTNGP03.phx.gbl...
>>>Re hello,
>>>>
>>>I m' sorry for my questions ..
>>>Under framework 1.1 with vb.net, i m using a StringWriter object to
>>>export in .xls file.
>>>To empty memory, I would like to use the propterty dispose on the
>>>object StringWriter.
>>>But i have received an error like this :
>>>>
>>>example :
>>>>
>>>Dim myStringWriter As System.IO.StringWriter = New
>>>System.IO.StringWriter
>>>...
>>>myStringWriter.Dispose(System.Boolean)(true)
>>>myStringWriter=Nothing
>>>>
>>>>>Error
>>>>
>>>BC30390: 'System.IO.StringWriter.Protected Overrides Sub
>>>Dispose(disposing As Boolean)' is not accessible in that context. it is
>>>protected..
>>>>
>>>>
>>>I can use the Close() method but i m not sure that this last one have
>>>the same effects for Garbage Collector ?
>>>Is it possible to use Dispose method with StringWriter object
>>>>
>>>>
>>>Thanks for you help
>>>fabrice
>>>>
>>>
>>>


>>
>>


>
>