[Gtk-sharp-list] Object madness.

Øyvind Hvamstad oyvind@hvamstad.net
04 Mar 2003 23:54:23 +0100


Hi.

This will not work! o is an Object and no method 'method()' exists
there. It is not supposed to work either. 

The below example does something, that perhaps is what you want? This
can also be done by interfacing.

using System;

public class Class1
{
  public virtual void foo() {
    Console.WriteLine("Class1");
  }
}

public class Class2 : Class1
{
  public override void foo() {
    Console.WriteLine("Class2");
  } 
}


public class Myclass
{
  public Myclass () {
    Class1 c = new Class2();
    c.foo();
  }

  public static void Main() {
    new Myclass();
  }
}

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?
> 
> public class InhClass
> {
> }
> 
> public class Class1 : InhClass
> {
> 	methods here
> }
> 
> public class Class2 : InhClass
> {
> 	methods here
> }
> 
> 
> public class myclass
> {
> 	Object o = new Object();
> 	
> 	public myclass ()
> 	{
> 		if (preference  == "pref" )
> 		{
> 			Class1 c = new Class1();
> 			o = c;
> 
> 			now access methods in Class1 via o.method()
> 		}
> }
> The compiler says System.Object does not contain a reference for
> o.method()
-- 
Øyvind Hvamstad <oyvind@hvamstad.net>