For example implicitly
MyClass myClass = new MyClass();
int i = myClass;
For example implicitly
MyClass myClass = new MyClass();
int i = myClass;
You need to define this in the MyClass
file.
public static implicit operator int(MyClass instance)
{
if (instance == null)
{
return -1;
}
return instance._underlyingValue;
}
class MyClass
{
public static implicit operator int(MyClass myClass)
{
// code to convert from MyClass to int
}
}
Take a look there : implicit
This MSDN entry covers what you want exactly, should do the trick.