c# operator overloading

josh BAUER 166 Reputation points
2021-03-08T10:13:21.213+00:00

I know that it is possible to overload operators in C# same as in c++.
In c++ I would do:
class string {
friend bool operator!=(const string& stString, const char* ndString);
};
bool operator!=(const string& stString, const char* ndString) {
return !(stString==ndString);
}
How to do this in C#?
I do:
class ww {
static public string operator +(string stString, string ndString) {
return "kk";
};
}
I got errors.

Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Sam of Simple Samples 5,546 Reputation points
    2021-03-08T18:31:15.097+00:00
    public class ww
    {
    public static bool operator != (ww stString, ww ndString)
    {
    return !(stString == ndString);
    }
    }
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.