Main Site Documentation

C# newb question


#1

I need to declare a int as a global variable to be seen by all the methods in my main file. I was trying this:

namespace FEZ_Domino_Application1
{
    public class Program
    {
        static PersistentStorage ps;  //storage device pointer
        static OutputPort LED;  //led to test button interrupts
        public int Screenselection = 0;  //going to use to have a global value of the screen position
        public static void Main()
        {

hoping that main and the following methods would be able to access the screenselection variable, however I am getting some strange errors that im not sure what it means.

The Error:

Error 1 An object reference is required for the non-static field, method, or property ‘FEZ_Domino_Application1.Program.Screenselection’ C:\Users\Aaron\documents\visual studio 2010\Projects\Program.cs 165 22 FEZ Domino Application1

I know this is not a forum for coding really, but I figured such a simple question couldn’t hurt.

Regards,
Aaron


#2

Just follow what the error says…make your variable static and it will work…why? because main is static so it can only use static variables


#3

just substitute the word public with the word static
you will be set to go.

static int Screenselection = 0;

#4

Thanks =)