That is because
p
variable is created, and thus is only accessible, in
Main
method. In clear: the
Program
instance
p
in your
Main
method is not the same
Program
instance as your program actually runs in.
You could put all but the
Main
method in its own class, an instance of which you would then instantiate inside the
Main
method.
Schematically:
public class SPWrapper
{
public IPAddress IP { get; protected set; }
public int Cmd_Port { get; protected set; }
}
class Program
{
private static SPWrapper p;
static void Main(string[] args)
{
p = new SPWrapper();
}
}
p
would then be accessible from everywhere inside the
Program
class.