Ok, this may sound like a very novice question.. i'm actually surprised i'm asking it. I can't seem to remember how to call a function from inside static void Main()
namespace myNameSpace
{
class Program
{
static void Main()
{
Run(); // I receive an error here.
Console.ReadLine();
}
void Run()
{
Console.WriteLine("Hello World!");
}
}
}
error:
An object reference is required for the non-static field, method, or property 'myNameSpace.Program.Run()'
You need to either make Run
a static
method or you need an object instance to call Run()
of. So your alternatives are:
1.) Use an instance:
new Program().Run();
2.) Make Run()
static:
static void Run()
{
/..
}
Declare your Run()
method as static too:
static void Run()
{
Console.WriteLine("Hello World!");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With