October 12th, 2010

This is a short post about the not so well known implicit and explict operators in C#. These operators are used for user-defined conversions of custom types, and their existence is an often overlooked feature of C# (at least overlooked by me, until recently).

An implicit cast occurs automatically when an implicit conversion operator has been defined and the two data types are compatible. An explicit cast is used when the two data types are not entirely compatible and requires a cast.

For example, after we defined an implict cast from List to DmCollection like this: