O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

23.2. Syntax of user-defined conversion method declarations

As with operator overloading, you use the operator keyword to declare the conversion method. The full syntax for the declaration of the conversion method is:

public static <explicit|explicit> operator conv_type_out (conv_type_in operand)

Additional notes

  • Besides classes, you can also write conversion methods for structs (see Chapter 26).

  • The conversion method must be static.

  • The conversion method must either return the type for which the conversion is defined, or take that type in as one of the method parameters.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required