I have this Simple Console program in .NET Core 3.1 with C# 8:
using System;
namespace ConsoleApp34
{
public interface ITest
{
public void test()
{
Console.WriteLine("Bye World!");
}
}
public class Test : ITest
{
public void CallDefault()
{
((ITest)(this)).test();
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var t = new Test();
t.CallDefault();
}
}
}
I don't understand why the cast is necessary in the line ((ITest)(this)).test();
Test is directly derived from ITest, so, by definition, 'this' IS ITest
Thank you.