0
How would you solve the part of the C# Intermediate code project that requires operator overloading?
So I've managed to solve this without operator overloading... But how do you solve it with operator overloading? I don't understand the syntax of operator overloading.
9 Answers
+ 5
Maybe you can share the task, and also add your code (as per the following instruction), where you attempt what you know from overloading, and someone can help you with what isn't working.
https://sololearn.com/compiler-playground/Wek0V1MyIR2r/?ref=app
+ 1
Here's my effort.
https://sololearn.com/compiler-playground/cGv12UNH5Khs/?ref=app
+ 1
when you overload an operator, you're basically returning a new class instance and initializing it with the combined properties of the two input objects.
0
My solution. (It works, but I didn't do what I'm supposed to do.)
https://sololearn.com/compiler-playground/cUlyABKPFJ5m/?ref=app
0
Managed to solve that one and was referring to something else
0
MattMad
your code is different from the one in my Android course, but maybe you want something like this:
https://sololearn.com/compiler-playground/cJgqb2a2PeVz/?ref=app
0
It works – but could you explain how it works?
0
Syntax, I mean
0
public static DancerPoints operator+(DancerPoints a, DancerPoints b)
{
return new DancerPoints($"{a.name} & {b.name}", a.points + b.points);
}
you return a new DancerPoints object with
name = $"{a name} & {b.name}"
and
points = a.points + b.points