+ 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
3 Antworten
+ 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
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?
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;
}