G
garyusenet
The following piece of code appears in an example i'm reading after the
class has been named.
public string userMessage;
However if i move that into my main method, i'm told that the keyword
public is not recognised. Why is this? I imagine that it might be
useful to reference a variable from outside of the Main() method and it
was my understanding that the public keyword allowed you do to this.
As an example:
This works...
-------------------------------------
using System;
namespace constructors
{
class test
{
// point of state data
public string userMessage;
public static void Main()
{
}
}
}
-------------------------------------
But this doesn't
-------------------------------------
using System;
namespace constructors
{
class test
{
public static void Main()
{
// i can't create a public string in the main method
public string userMessage;
}
}
}
class has been named.
public string userMessage;
However if i move that into my main method, i'm told that the keyword
public is not recognised. Why is this? I imagine that it might be
useful to reference a variable from outside of the Main() method and it
was my understanding that the public keyword allowed you do to this.
As an example:
This works...
-------------------------------------
using System;
namespace constructors
{
class test
{
// point of state data
public string userMessage;
public static void Main()
{
}
}
}
-------------------------------------
But this doesn't
-------------------------------------
using System;
namespace constructors
{
class test
{
public static void Main()
{
// i can't create a public string in the main method
public string userMessage;
}
}
}