public class Faranheit
{
public float Digree { get; set; }
public Faranheit(float f)
{
Digree = f;
}
public static implicit operator Celcius(Faranheit f)
{
return new Celcius((5.0f / 9.0f) * (f.Digree - 32));
}
public static implicit operator Faranheit(Celcius c)
{
return new Faranheit((9.0f / 5.0f) * c.Digree + 32);
}
}
public class Celcius
{
public float Digree{get;set;}
public Celcius(float c)
{
Digree = c;
}
}
I am just confused, where to put the conversion methods exactly..
It works fine even if I put one method in one class and other in the other, or I interchange them or even if I put both of them in any of the two classes..
But if I put it outside these two classes it doesn't work (compile error)..
Could please someone put some light on this..
EDIT:
if it allows the conversion methods to be in either of the class, why doesn't it allow the conversion method to be in a separate class??