I'm learning C# now. The tutorial doesn't make it clear when to use keyword implicit
or explicit
when overloading conversion operators.
The example it provides is like this:
When
Class1
contains a field of typeint
andClass2
contains a field of typedouble
, we should define an explicit conversion fromClass2
toClass1
, and an implicit conversion fromClass1
toClass2
.
The tutorial doesn't say what will happen if I use the wrong keyword.
But if Class1
contains a complex subclass and Class2
contains a different subclass, which keyword should I use between implicit
and explicit
? Can anyone gives a clear explanation? Thanks a lot.