Can I make a generic optional, defaulting to a certain class?

前端 未结 2 1473
-上瘾入骨i
-上瘾入骨i 2021-01-03 18:05

My question is related to Is there a reasonable approach to "default" type parameters in C# Generics?, but using an inner generic class that approach doesn\'t work

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 18:49

    Another interesting thing I just found is that you can create generic classes with the same name but different signatures.

    class Foo { 
    
    }
    
    class Foo { 
    
    }
    

    then you can call either one of them like follows:

    new Foo();
    new Foo();
    new Foo();
    

    I just thought it was interesting that despite both classes having the same name they can co-exist because they have different signatures.

    I guess this is how the Tuple class works

    public class Tuple 
    { 
    ...
    

提交回复
热议问题