String override question

  • Thread starter Thread starter Patrick De Ridder
  • Start date Start date
P

Patrick De Ridder

Is it possible to change this function into
a string override? So I could just say
d.ToString()
Patrick

private string reformat(double d)
{
NumberFormatInfo nfi = new CultureInfo("").NumberFormat;
nfi.NumberDecimalSeparator=".";
nfi.NumberGroupSeparator="";
return d.ToString( "N", nfi ) ;
}
 
Patrick,
Is it possible to change this function into
a string override? So I could just say
d.ToString()

No, since you can't derive from Double (or any other value type).

You could possibly define your own struct with an implicit conversion
operator from double, and then write your own ToString implementation
for it.



Mattias
 

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

Back
Top