c# - .NET interface/constraint for object that implements certain operators -
i making generic method , wondering if there way of adding constraint generic type t
, such t
has operator, +, +=, -, -=, etc.
public void testadd<t>(t t1, t t2) { homecoming t1 + t2; }
produces next error text:
operator '+' cannot applied operands of type 't' , 't'
i searched around on google/so while , couldn't find related.
i think cannot done
you can less fancy :
interface iaddable { void add(object item); } ... public void testadd<t>(t t1, t t2) t : iaddable { homecoming t1.add(t2); }
c# .net generics operators operator-overloading
No comments:
Post a Comment