简体   繁体   中英

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? 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?

No.

Keeping it short as this question has been duplicated many times.

eg here

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM