Generic method where T is type1 or type2

For ReferenceType objects you can do

public void DoIt<T>(T someParameter) where T : IMyType
{

}

public interface IMyType
{
}

public class Type1 : IMyType
{
}

public class Type2 : IMyType
{
}

For your case using long as parameter will constrain usage to longs and ints anyway.

public void DoIt(long someParameter)
{

}

to constrain to any value types (like: int, double, short, decimal) you can use:

public void DoIt<T>(T someParameter) where T : struct
{

}

for more information you can check official documentation here

Leave a Comment