Is there anyway to define type parameter T
as the ones that define operator overloading? Take for example, I need to create a generic Add
function with the parameter T
. Obviously, the T must defined the +
operator, ie,
public static T operator +(T c1,T c2)
{
// plus operation
}
Is there anyway to constraint T
so that it is restricted to the types that overload the operators?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.