C# generics contraints propagation

后端 未结 5 1353
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-10 06:11

This example is a simplification of the real problem, but how can I get this to compile? I would expect the generics constraints to propagate.

Since T is a TClass and TC

5条回答
  •  猫巷女王i
    2021-02-10 06:24

    Looks like you're just curious why you can't do so. And you're not interested in working example like this:

    public class MyClass where TClass : class
    {
        public void FuncA() where Ta : class
        {
        }
    
        public void FuncB() where Tb : TClass
        {
        }
    
        public void Func()
        {
            FuncA();
            FuncB();
        }
    }
    

提交回复
热议问题