[Gtk-sharp-list] Object madness.

George Farris farrisg@mala.bc.ca
04 Mar 2003 20:33:05 -0800


On Tue, 2003-03-04 at 20:37, JPerrin wrote:
> -----Original Message-----
> From: gtk-sharp-list-admin@lists.ximian.com
> [mailto:gtk-sharp-list-admin@lists.ximian.com] On Behalf Of George
> Farris
> Sent: Tuesday, March 04, 2003 8:34 PM
> To: gtk-sharp-list
> Subject: Re: [Gtk-sharp-list] Object madness.
> 
> 
> > Hmm in my "Teach yourself C# in 21 days" it does this:
> > 
> > Object x = new PI();
> > Console.WriteLine("Type: {0}", x.GetType());
> > 
> > which returns "Type: PI"
> > so..if type is PI why wouldn't it then have access to PI's methods?
> 
> This is pretty basic object-oriented stuff.  You can have an object (as
> in System.Object) that is of a type: whatever (in C#, everything is an
> object), but in order to access the methods of that type you'd have to
> cast it.
> 
> So if you know that an object is actually also a PI, you can cast it
> like so:
> 
> PI pi = (PI)x;
> 
> So the answer to your question... Yes, the object has access to PI's
> methods, but only if you tell the compiler that the object *is* a PI.  
> 
> JP
> 

Yes I see.  I guess what I was trying to accomplish is something that
can be done under Python, basically:

if self.prefs.transmitAgent == "hylafax":
    # Make a fax instance
    self.fax = hylafax(self.prefs)
if self.prefs.transmitAgent == "mgetty":
    self.fax = mgetty(self.prefs)
if self.prefs.transmitAgent == "efax":
    self.fax = efax(self.prefs)