|
June 24, 2002 Polymorphic ToString() Tips: June 2002
Yehuda Shiran, Ph.D.
|
|
The method ToString() is a good example for polymorphism. This method is defined for the Object class that is the base class for every class in the .NET framework. You can use this method for objects that are of type Object, int, or double. You can also redefine this method for a new type of object you create with a new class, without changing the way you call the method.
The following example includes the main program section and a definition of class
and returns "foo". The main program calls ToString() with each one of the four variables: o, i, d, and b. Here is the code:
To learn more about JScript .NET, go to Column 111, JScript .NET, Part V: Polymorphism.
People who read this tip also read these tips: Look for similar tips by subject: |