Look at the following code:
class A
{
public string DoSomething(string str)
{
return "A.DoSomething: " + str;
}
}
class B : A
{
}
static class BExtensions
{
public static string DoSomething(this B b, string str)
{
return "BExtensions.DoSomething: " + str;
}
}
class Program
{
static void Main(string[] args)
{
var a = new A();
var b = new B();
Console.WriteLine(a.DoSomething("test"));
Console.WriteLine(b.DoSomething("test"));
Console.ReadKey();
}
}
The output of the code is:
A.DoSomething: test
A.DoSomething: test
When it compiles it gives no warnings.
My questions are: why there are no warnings when that code compiles and what exactly happens when the DoSomething
method is called?