When you execute Program1 : Program
, you are reporting that all instances of Program1 are not only of type Program1, but also of type Program, because it inherits it.
But when you do Program1<T>
, you say that program 1 can have any independent type parameter in addition to its own type, to do something with this independent type.
If you use Program1 : Program
, your static method can do the following:
class Program1 : Program { public static void check() { Program.Main()
In the case of using Program1<T>
I do not see anything that explains this use, unless you are trying to do something else that we did not read in the question. Here T is not really a program, even if you set the restriction the same way you do. T is a simple generic type. The reasons for using it are to allow your class to work with different types. If you work with only one type, there is no reason to use a generic type, just use Program
.
source share