I recently discovered the wonders of implicit operator overloading in C#. I was wondering, if you have both “ways” of implicit operator overloading, such as:
public static implicit operator FooType(int num)
{
return new FooType(num);
}
public static implicit operator int(FooType fooType)
{
return fooType.IntValue;
}
- Is there a name for that design pattern?
- Is there a predefined .NET interface that I can use, say
ICastable<int>?
1 Answer