Consider the following static generic method:
public class Foo
{
public static void Test<T>(T arg)
where T : FrameworkElement
{
}
}
I can simply call it like below and T will be implied to be a Button
from the passed-in argument:
var myButton = new Button();
Foo.Test(myButton);
However, for the following generic class...
public class Laa<T>
where T : FrameworkElement
{
public Laa(T element)
{
}
}
This code won't compile.
var myButton = new Button();
var laa = new Laa(myButton);
Instead, I have to explicitly provide the type like so.
var myButton = new Button();
var laa = new Laa<Button>(myButton);
I thought T
would be implied from the provided argument but that doesn't seem to be the case.
I suspect the reason is because there is no class Laa
--the class is actually Laa<Button>
--so it doesn't know what to construct, but that's just a guess.
Even so, isn't there enough information for the compiler to figure this out? There is no class Laa
but there is a generic Laa<T>
which would be satisfied with the provided argument.