October 2nd, 2013, 06:09 PM
C# How to call a private method
Hi I'm very new to c#.
I am trying to call a private method Area with the parameters I want and print it out. I am getting an error message and believe I am calling it wrongly. The codes as follows. Please advice. Thank you.
static void Main(string args)
double answer = Area(10);
private double Area(int radius)
double pi = 3.14;
return pi * radius * radius;
October 2nd, 2013, 06:58 PM
As you've said Area is a private method, but it's also an instance method. You need an actual instance of the class (Program) to be able to call it.
Make the Area method static. Like Main.