+ 1

C# Overloading operator + question [answered]

Hey everyone. My brain is somehow not working correctly and I need some advice on how to proceed with this challenge (see details in code). I am confused as to how exactly I need to add first the ints and then put the strings together as described. Any hints are very welcome. https://code.sololearn.com/chIHehLlytup/#cs

17th Feb 2022, 8:44 AM
The_Fox
The_Fox - avatar
3 Respostas
+ 1
first you will to declare string variable to hold the string concatonation form a and b name property hint string newName = a.name + " & " + b.name; second you will declare int variable to hold the sum of a.points and b.points then return new object of DancerPoints with this new properties values
17th Feb 2022, 9:49 AM
Mohamed
Mohamed - avatar
0
Thank you MOHAMED. I am still stuck... public static DancerPoints operator+(DancerPoints a, DancerPoints b) { DancerPoints c = new DancerPoints(); string newName = a.name + " & " + b.name; int newPoint = a.points + b.points; c.name = newName; c.points = newPoint; return c; } This gives me the following error: error CS7036: There is no argument given that corresponds to the required formal parameter 'name' of 'DancerPoints.DancerPoints(string, int)' Do I need to initialise c in a different way?
17th Feb 2022, 10:01 AM
The_Fox
The_Fox - avatar
0
I think I got it! Thanks again ;) public static DancerPoints operator+(DancerPoints a, DancerPoints b) { string newName = a.name + " & " + b.name; int newPoint = a.points + b.points; DancerPoints c = new DancerPoints(newName, newPoint); return c; }
17th Feb 2022, 10:16 AM
The_Fox
The_Fox - avatar