Your method has the wrong signature. It should be private static int sumOfNumbers(int x, int y)
.
edit: I've been asked to put a little more explanation around this. A static method, like Main
in your example, doesn't belong to a particular instance of an object. It belongs to its class, Program
. A method without the static modifier belongs to a particular instance of the class. This difference means that an "objectless" static method (Main
) can only work directly with methods that are static, or by instantiating an object and then invoking that method on the object.
This second method would look like:
var foo = new Program();
Console.WriteLine(foo.sumOfNumbers(3,2))
I would continue to recommend modifying the method to be static. I infer from your Main
method that you're writing a console app, and it would be unconventional (in my experience) to instance such a class.