I want to create a class like this
public class MyClass<T> where T:int || T:decimal || T:double || T:float ||T:long
{
public T DoSomething()
{}
}
Is it possible to do this in C#?
I want to create a class like this
public class MyClass<T> where T:int || T:decimal || T:double || T:float ||T:long
{
public T DoSomething()
{}
}
Is it possible to do this in C#?
 
    
    You can't do this, but you can use struct constraint which means that type argument must be a value type:
public class MyClass<T> where T: struct
{
  public T DoSomething()
  {  
    // your code
  }
}
Take a look at Constraints on Type Parameters
