Method unhiding in C#

In C++, the "using" keyword unhides methods, is there a C# e

Page 1 of 1

1 Replies - 1100 Views - Last Post: 31 January 2010 - 11:08 AM Rate Topic: -----

#1 mrtimuk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 31-January 10

Method unhiding in C#

Post icon  Posted 31 January 2010 - 10:54 AM

Hi, first post please be nice ;)

In C++ I could do this:

#include <iostream>
 
class base {
public:
  base() {}
  void foo(int i) { std::cout << "base int"; }
};
 
class deriv : public base {
public:
  deriv() {}
  void foo(long i) { std::cout << "deriv long"; }
  using base::foo;
 
  void go() { foo((int)1); }
};
 
int main() {
  deriv d;
  d.go();
  return 0;
}



The result prints "base int" because the "using" statement unhides the base::foo method. See this code run in a pasebin

My question is, is there an equivalent to the "using" keyword to unhide base methods in C#?

I want to write something like this to make all the overrides visible:
using System;
 
public class baseclass {
  public baseclass() {}
  public void foo(int i) { Console.WriteLine("baseclass int"); }
}
 
class deriv : baseclass {
  public deriv() {}
  public void foo(long i) { Console.WriteLine("deriv long"); }
  using baseclass.foo;
 
  public void go() { foo((int)1); }
}
 
public class app {
 
  public static void Main() {
	deriv d = new deriv();
	d.go();
  }
}


Please use this pastebin to test your code before replying- it should return "baseclass int" when the method has been unhidden.

Thanks :)

Is This A Good Question/Topic? 0
  • +

Replies To: Method unhiding in C#

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Method unhiding in C#

Posted 31 January 2010 - 11:08 AM

There is no such using keyword like the above but how about this:

Change this:
public void go() { foo((int)1); }



into this:
// call baseclass' foo() method
public void go() { base.foo(1); }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1