0

I need help with this: Method overload C#

Complete the Add () method so that it calculates the sum of two numbers given as arguments. Overload it to be able to do the same operation with double type values. The method calls are already written. This is the code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Console.WriteLine(Add(10, 12)); Console.WriteLine(Add(1.5, 2.9)); } //completa el método para sumar static int Add( a + b) { } //sobrecárgarlo para el tipo doble static double Add( a + b) { } } }

26th Jun 2021, 1:33 AM
Alex Narváez
Alex Narváez - avatar
5 odpowiedzi
+ 3
Change Add() to public int Add(int a, int b) { return a+b; } That should fix the error in your code as you can only get parameters in functions not do anything to them when accepting them
26th Jun 2021, 1:35 AM
Ollie Q
Ollie Q - avatar
+ 1
Ollie Q. Thank you very much for your help. It helped me a lot
26th Jun 2021, 1:39 AM
Alex Narváez
Alex Narváez - avatar
+ 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { Console.WriteLine(Add(10, 12)); Console.WriteLine(Add(1.5, 2.9)); } //complete the method to sum static int Add(int x, int y) { return x+y; } //overload it for double type static double Add(double x, double y) { return x+y; } } }
18th Feb 2023, 6:44 PM
Guy Martial KEYOU
0
No problem, happy coding!
26th Jun 2021, 1:39 AM
Ollie Q
Ollie Q - avatar
0
public int Add(int a, int b) { int sum = a + b; return sum; } static double Add( double a, double b) { double sum = a + b; return sum; } it should add parameter in each function and operator inside of it
28th Nov 2022, 3:41 AM
Yusril Arzaq
Yusril Arzaq - avatar