Jack

Jack

  • NA
  • 4
  • 0

Newbie overriding problem

Dec 25 2008 3:25 AM
I can't work out how to override a function, I spent 3 hours reading and searching to no luck.

What I am trying to do is to have a function lets say called blah in a class lets say class1 that will return "One" to me. Then in another class, say class2 another function also called blah would return "Two".
Up to here it is ok

class TestClass
{
   public class Class1
   {
      public virtual blah()
      {
         return "One";
      }
   }
   class Class2: Class1
   {
      public override blah()
      {
         return "Two";
      }
   }

Then in my main I would like that depending on a variable or button status the first or second blah() is called but the command to call it must be the same, I cant one time use
Class1 s = new blah();

and the second time use

Class2 s = new blah(x);

That part I can't work out how to do. It is probably ultra simple or maybe I took the wrong way.

In any case, your help is much appreciated.




 

Answers (1)