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.

26th Feb 2025, 6:46 AM
MattMad
MattMad - avatar
9 Respuestas
+ 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
26th Feb 2025, 7:25 AM
Ausgrindtube
Ausgrindtube - avatar
M
26th Feb 2025, 3:45 PM
Ausgrindtube
Ausgrindtube - avatar
M
+ 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.
27th Feb 2025, 3:09 PM
Bob_Li
Bob_Li - avatar
0
My solution. (It works, but I didn't do what I'm supposed to do.) https://sololearn.com/compiler-playground/cUlyABKPFJ5m/?ref=app
26th Feb 2025, 12:24 PM
MattMad
MattMad - avatar
0
Managed to solve that one and was referring to something else
26th Feb 2025, 5:22 PM
MattMad
MattMad - avatar
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
26th Feb 2025, 5:34 PM
Bob_Li
Bob_Li - avatar
0
It works – but could you explain how it works?
27th Feb 2025, 3:05 PM
MattMad
MattMad - avatar
0
Syntax, I mean
27th Feb 2025, 3:30 PM
MattMad
MattMad - avatar
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
27th Feb 2025, 3:42 PM
Bob_Li
Bob_Li - avatar