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.
The
/
operator is a "binary" operator, meaning that it takes two arguments:a / b
. The way you've written this, it's trying to overload it as a "unary" operator, such asa++
.Something like this ought to work, assuming your class is called "MyObject".
Usage:
You can overload the division operator, but:
So for example: