Overload division in C#

I want to overload division operator in my C# class. So, i wrote:

public string[] operator/ (object obj) {

}

And got error: "Parser error: Overloadable unary operator excepted".
So, i cant overload that operator?
On the MSDN i don't see any example: http://msdn.microsoft.com/en-us/library/3b1ff23f.aspx
Thanks.

//i'm using MonoDevelop on Ubuntu 14.10, if it's needed.

Jon Skeet
people
quotationmark

You can overload the division operator, but:

  • It must always be a binary operator - you've only provider one operand
  • It must always be static
  • At least one of the operand types must be the type you're declaring it in

So for example:

using System;

class Program
{
    public static string operator/ (Program lhs, int rhs)
    {
        return "I'm divided!";
    }

    static void Main(string[] args)
    {
        Console.WriteLine(new Program() / 10);
    }
}

people

See more on this question at Stackoverflow