Object reference not found in Main()

Posted on 2005-04-26
Medium Priority
Last Modified: 2010-04-16

When i try to build this

class Class1
            static void Main(string[] args)
            string s = "C# Programming for me";

I get this error "An object reference is required for the nonstatic field, method, or property 'PigLatin.Class1.s' "

Is this because Main is a static method and cannot operate with nonstatic fields? I thought that s that i use in the WriteLine statement is the actual reference to the string object i declared at class level. So why cant it find it?
Question by:Kokas79
1 Comment

Accepted Solution

NipNFriar_Tuck earned 400 total points
ID: 13870277
You are correct, main is a static field and cannot access an instance level variable.  Try doing this...

class Class1
          static void Main(string[] args)
                Class1 c = new Class1();

          public string s = "C# Programming for me";

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question