C# Generic Operators

前端 未结 5 1761
心在旅途
心在旅途 2020-11-27 07:25

I am trying to implement a generic operator like so:

class Foo
{
   public static T operator +(T a, T b) 
   {
       // Do something with a and b t         


        
5条回答
  •  萌比男神i
    2020-11-27 07:54

    You can just define operator in a generic class Foo.

    You can also create real generic operators, but C# compiler won't use them.

    [System.Runtime.CompilerServices.SpecialName]
    public static T op_Addition(T a, T b) { ... }
    

提交回复
热议问题