This documentation is archived and is not being maintained.

6.4.1 Permitted user-defined conversions

Visual Studio .NET 2003

C# permits only certain user-defined conversions to be declared. In particular, it is not possible to redefine an already existing implicit or explicit conversion. A class or struct is permitted to declare a conversion from a source type S to a target type T only if all of the following are true:

  • S and T are different types.
  • Either S or T is the class or struct type in which the operator declaration takes place.
  • Neither S nor T is object or an interface-type.
  • T is not a base class of S, and S is not a base class of T.

The restrictions that apply to user-defined conversions are discussed further in Section 10.9.3.

Show: