Information Technology Reference
In-Depth Information
class Employee : Person { }
class Person
{
public string Name;
public int Age;
// Convert a Person object to an int
public static implicit operator int(Person p) {
return p.Age;
}
}
class Program
{
static void Main( )
{
Employee Bill = new Employee();
Bill.Name = "William"; Bill.Age = 25;
Convert an Employee to a float.
float FVar1 = Bill;
Console.WriteLine("Person Info: {0}, {1}", Bill.Name, FVar1);
}
}
Figure 18-28 illustrates the conversion.
Figure 18-28. Conversion of Employee to float
Search WWH ::




Custom Search