In C #, why use Where T: ConcreteClass?

I came across some code (created by a code generation wizard, not a person) that looks like this:

public class xxxViewModel<T> : SomeBaseClass<T> where T : xxx

So xxx is really a class, and only one concrete class. I'm not sure why developers would do this, and not:

public xxxViewModel : SomeBaseClass<xxx>

The class (xxxViewModel <T>) is not used as a general class - it allows only T to be one type of class - xxx, and it does not have counters, so the actual type of the class does not matter as it would be in the list <T>.

What is the reason for defining a general class, where T can only be a specific class?

0
source share
3 answers

SomeBaseClass <T> T , , () xxx xxx xxx. :

class SomeBaseClass<T> {
    public T Create(){ return new T();}
}

xxxViewModel <T> then SomeBaseClass.Create , , T-. xxx - , , .

? xxx , , .

0

, xxx (, ). ,

T xxx , xxx

+1

# , :

public class xxxViewModel<T> : SomeBaseClass<T> where T : xxx

:

"the generic parameter must implement interface xxx"

, , .

0

Source: https://habr.com/ru/post/1688667/


All Articles