Why does a static method on a generic type require a Type parameter?

前端 未结 4 1988
说谎
说谎 2021-01-18 08:42
public class BinarySearchTree
where T : IComparable
{
    public static BinarySearchTree InitializeSampleCharacterBST()
    {
        v         


        
4条回答
  •  忘掉有多难
    2021-01-18 09:26

    Because the type itself is Generic, you have to provide a type argument, even if the static method you are interested in does not make use of that type argument. Its just the nature of generics in C#...they don't exist in a non-generic form at any time. If they did, that would cause conflicts with a non-generic version of the same type.

提交回复
热议问题