[Gtk-sharp-list] Object madness.
George Farris
farrisg@mala.bc.ca
04 Mar 2003 19:34:06 -0800
Hmm in my "Teach yourself C# in 21 days" it does this:
Object x =3D 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?
On Tue, 2003-03-04 at 14:54, =D8yvind Hvamstad wrote:
> Hi.
>=20
> This will not work! o is an Object and no method 'method()' exists
> there. It is not supposed to work either.=20
>=20
> The below example does something, that perhaps is what you want? This
> can also be done by interfacing.
>=20
> using System;
>=20
> public class Class1
> {
> public virtual void foo() {
> Console.WriteLine("Class1");
> }
> }
>=20
> public class Class2 : Class1
> {
> public override void foo() {
> Console.WriteLine("Class2");
> }=20
> }
>=20
>=20
> public class Myclass
> {
> public Myclass () {
> Class1 c =3D new Class2();
> c.foo();
> }
>=20
> public static void Main() {
> new Myclass();
> }
> }
>=20
> On Tue, 2003-03-04 at 22:40, George Farris wrote:
> > I want to be able to do the following but it doesn't really seem to
> > work. From what I have read it should. Any ideas?
> >=20
> > public class InhClass
> > {
> > }
> >=20
> > public class Class1 : InhClass
> > {
> > methods here
> > }
> >=20
> > public class Class2 : InhClass
> > {
> > methods here
> > }
> >=20
> >=20
> > public class myclass
> > {
> > Object o =3D new Object();
> > =09
> > public myclass ()
> > {
> > if (preference =3D=3D "pref" )
> > {
> > Class1 c =3D new Class1();
> > o =3D c;
> >=20
> > now access methods in Class1 via o.method()
> > }
> > }
> > The compiler says System.Object does not contain a reference for
> > o.method()