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
 
Back
Top