23.2 Syntax of user-defined conversion method declarations


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 <explicitexplicit> 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.



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net