I have created a console application and declared a string a and assigning in code I am getting error.
namespace ConsoleApplication1
{
class Program
{
string a;
static void Main(string[] args)
{
Console.WriteLine("Hello!");
}
}
}
An object reference is required for the non-static field, method Error in console application
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Sam HobbsRank #107 · 20.5K reputationPosted Nov 18, 2009, 12:49 PM EST
This applies to member functions for console programs also.
jingeRank #2,527 · 554 reputationPosted Nov 18, 2009, 2:23 PM EST
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 18, 2009, 2:37 PM EST
Just Modify Your Code like Below and it will work fine :)
class Program
{
static string a="Hello";
static void Main(string[] args)
{
Console.WriteLine(a);
}
}
check "Do you like this answer check box " if it helps you :)