You need a common function.
public T YourFunctionName<T>(T value) { return value; }
Keep in mind that the compiler can only assume that T is an object, so you can only perform basic operations such as Equals, ToString, etc. You can add a where constraint to the generic method to suggest that the parameter is something concrete, like a class or structure.
public T YourFunctionName<T>(T value) where T : class { return value; }
Although there is a good chance that you can really just use a base class or interface to handle multiple types the same way. When using the general method, you will quickly understand if you cannot do what you can do with this template. If your restriction leads you to limit your general method to only working with a particular type of interface, you probably just want this method to be part of the interface.
source share