How to overload the operator % (remainder after dividing) in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication1
{
    class Test
    {
        public float _n;

        public static Test operator % (Test x, Test y)
        {
            Test t = new Test();

            t._n = x._n % y._n;

            return t;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Test a = new Test();
            a._n = 10;

            Test b = new Test();
            b._n = 3;

            Test t = a % b;
            Console.WriteLine(t._n);
        }
    }
}

/*
run:
   
1
      
*/

 



answered Mar 16, 2017 by avibootz

Related questions

...