Multiple constrains single generics parameter

Viewed 36

Here is an example of declaring a single parameter generics class with single constraints.

public class TestClass<T> : ITestClass<T> where T : Teacher

I am looking for a way to declare the TestClass with multiple constraints. Where I will be able to use an interface for different classes.

How can I do something like this?...

public class TestClass<T> : ITestClass<T> where T : Teacher, Student, new()

My classes look like

public class Teacher{
    public string Name { get; set; }
    public string Designation { get; set; }
}

public class Student{
    public string Name { get; set; }
    public int Roll { get; set; }
    public string Department { get; set; }
}
0 Answers
Related