Information Technology Reference
In-Depth Information
This code produces the following output:
Person Info: Bill, 25
Person Info: Nemo, 35
If you had defined the same conversion operators as
explicit
rather than
implicit
, then
you would have needed to use cast expressions to perform the conversions, as shown here:
...
↓
public static explicit operator int( Person p ) {
return p.Age;
}
...
static void Main( )
{
...
Requires cast expression
↓
int age = (int) Bill;
...