[英]Defining Typed Parameters as the Ones that Define Operator Overloading
Is there anyway to define type parameter T
as the ones that define operator overloading? 无论如何,是否将类型参数
T
定义为定义运算符重载的参数? Take for example, I need to create a generic Add
function with the parameter T
. 例如,我需要使用参数
T
创建一个通用的Add
函数。 Obviously, the T must defined the +
operator, ie, 显然,T必须定义
+
运算符,即
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? 无论如何,约束
T
会被限制为使运算符超载的类型吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.