public class BinarySearchTree<T>
where T : IComparable<T>
{
public static BinarySearchTree<char> InitializeSampleCharacterBST()
{
var bst = new BinarySearchTree<char>();
bst.Insert('F');
bst.Insert('B');
bst.Insert('A');
bst.Insert('D');
bst.Insert('C');
bst.Insert('G');
bst.Insert('I');
bst.Insert('H');
return bst;
}
class Program
{
static void Main(string[] args)
{
var bst = BinarySearchTree.InitializeSampleCharacterBST();
}
}
Why is this illegal? It's expecting me to provide a type parameter to the method call for the class which makes no sense. A generic class or method has no use for a type parameter in a static context.
It wants me to write the call like this:
var bst = BinarySearchTree<foo>.InitializeSampleCharacterBST();
Where foo can be any type I want regardless of the fact that the static method call returns a specifically typed generic object.