c# - Define a class MyClass<T> or a function MyFunction<T>(T x) where T can only by a type that implements IMyInterface -


i want define class myclass<t> , particular function myfunc<t>, want force t inherit (in way) interface or class. let's call imyinterface.

the way knowledge of c# allows me define generic class, check if inherits (see how check if type subtype or type of object? example), , throw exception otherwise.

is there way force @ compile-time, rather runtime?

generic type constraints:

public void myfunc<t>() t : imyinterface { } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -