This question came to my mind while I am reading the post Why doesn't C# support multiple inheritance? from MSDN Blog.
At first look at the following code:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class A
{
int num;
public A()
{
num = 0;
}
public A(int x)
{
num = x;
}
public override int GetHashCode()
{
return num + base.GetHashCode();
}
}
class B : A
{
int num;
public B()
{
num = 0;
}
public B(int x)
{
num = x;
}
public override int GetHashCode()
{
return num + base.GetHashCode();
}
}
class Program
{
static void Main(string[] args)
{
A a = new A();
B b = new B();
Console.Write(a.GetHashCode() + " " + b.GetHashCode());
Console.Read();
}
}
}
Object
class is the ultimate base class of all classes. So it is the base class of A
and B
both in my program and also make A
as a base class of B
. So B
has now two base class, one is A
and another is Object
. I override one method GetHashCode()
of Object
Class in class A
and B
both. But in class B
, base.GetHashCode()
method returns the return value of GetHashCode()
method of class A
. But I want this value from Object
class. How can I get that?