Why the below code would call the public void Func(object o)
even if i call it with int like so int i = 10;
Is it because all types derived from System.Object?
using System;
public class Program
{
static void Main(string[] args)
{
Derived d = new Derived();
object i = 10;
d.Func(i);
Console.ReadKey();
}
}
public class Base
{
public virtual void Func(int x)
{
Console.WriteLine("Base.Func(int)");
}
}
public class Derived : Base
{
public override void Func(int x)
{
Console.WriteLine("Derived.Func(int)");
}
public void Func(object o)
{
Console.WriteLine("Derived.Func(object)");
}
}
please let me know why if it is correct.