November 2001
Beginner to intermediate
816 pages
16h 3m
English
Conversions with simple types are easy. It's just a matter of putting a cast operator in front of the variable being converted from. For complex types, the expression syntax is the same. However, there's a lot of work going on behind the scenes to make sure complex type conversions happen properly. This section shows how to implement conversions on structs, complex value types.
A conversion definition can be either implicit or explicit. What is important is that one of the types being converted must be the same type as the enclosing class or struct. The following is the signature for defining a conversion operator.
public static convType operator toType(fromType typeName)
{
// conversion code
}
The public and static
Read now
Unlock full access