I have such example
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Boo();
}
interface IBASE_TYPE { };
interface IFOO<TYPE>: IBASE<TYPE>
where TYPE: IBASE_TYPE
{ };
interface IBASE<TYPE> { };
class A : IBASE_TYPE { }
class B : IBASE_TYPE { }
class OneChild : IFOO<A> { }
class SecondChild : IFOO<B> { }
void Execute(IFOO<IBASE_TYPE> item)
{
if (item == null)
{
Console.WriteLine("item is null");
}
}
void Boo()
{
var oneChild = new OneChild();
var secondChild = new SecondChild();
Execute(oneChild as IFOO<IBASE_TYPE>);
Execute(secondChild as IFOO<IBASE_TYPE>);
}
}
And log here is
item is null
item is null
It is not obvious for me... What is the problem here?
I don't expect that item is null
...
P.S.
Look at this, it is like the same example, but here it is works
interface ONE { }
class G : ONE { }
class Y : ONE { }
void SomeMethod()
{
var g = new G();
var Y = new Y();
More(g);
More(Y);
}
void More(ONE item)
{
if (item == null)
{
Console.WriteLine("item is null");
}
}
So, what is the diff?