Previous Page
Next Page

Chapter 19 Quick Reference

To

Do this

Implement an operator.

Write the keywords public and static, followed by the return type, followed by the operator keyword, followed by the operator symbol being declared, followed by the appropriate parameters between parentheses. For example:

struct Hour 
{ 
    ... 
    public static bool operator==(Hour lhs,
        Hour rhs)s
    { 
        ... 
    } 
    ... 
}

Declare a conversion operator.

Write the keywords public and static, followed by the keyword implicit or explicit, followed by the operator keyword, followed by the type being converted to, followed by the type being converted from as a single parameter between parentheses. For example:

struct Hour 
{ 
    ... 
    public static implicit operator Hour(int arg) 
    { 
        ... 
    } 
    ... 
} 

Previous Page
Next Page