Re: An object reference is required for the non-static field, method, or property
- From: Progress City <progresscity@xxxxxxxxx>
- Date: Sun, 27 Jan 2008 11:33:09 -0800 (PST)
On Jan 27, 11:25 am, Jon Skeet [C# MVP] <sk...@xxxxxxxxx> wrote:
Progress City <progressc...@xxxxxxxxx> wrote:
Compiling the code below gives me the following error
"An object reference is required for the non-static field, method, or
property"
How do I create an object reference for the array "a"?
You'd have to create a new instance of Program, e.g.:
static void Main(string[] args)
{
Program p = new Program();
for (int n = 0; n < 4; n++)
Console.WriteLine(p.a[n]);
Console.ReadKey();
}
Alternatively, make "a" static.
My guess is you're just starting out in C# - in which case a good book
would be a better place to start than newsgroups. It's not that we
dislike answering simple questions, it's just that you'll make progress
faster with a book :)
--
Jon Skeet - <sk...@xxxxxxxxx>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
World class .NET training in the UK:http://iterativetraining.co.uk
Thanks for your incredibly quick reply!
.
- Follow-Ups:
- References:
- An object reference is required for the non-static field, method, or property
- From: Progress City
- Re: An object reference is required for the non-static field, method, or property
- From: Jon Skeet [C# MVP]
- An object reference is required for the non-static field, method, or property
- Prev by Date: Re: An object reference is required for the non-static field, method, or property
- Next by Date: Re: Objects Persist Across Threads - Please Help.
- Previous by thread: Re: An object reference is required for the non-static field, method, or property
- Next by thread: Re: An object reference is required for the non-static field, method, or property
- Index(es):
Relevant Pages
|