Welcome to SO.
as you know you cannot have same variable name used in a method
here is what you need
{
int AddNumbers(int num1, int num2) //Here's where the error comes
{
int result = num1 + num2;
return result;
}
int num2 = 10;
int num3 = 20;
AddNumbers(num2, num3);
}
you can have something like this:
class Program
{
int p = 0;
public static void Main(string[] args)
{
int num1 = 10;
int num2 = 20;
int num = Method1(num1,num2);
Console.WriteLine(num);
}
public static int Method1(int num1, int num2)
{
p = num1 + num2;
return p;
}
}
8
solved Error when calling a function in C# because variable is used in parameter [closed]