I am having a problem in my code. I guess this is pretty straight forward, but I lack experience in OOP and C# so I have to ask you.
My code looks like this:
namespace RR
{
static class Program
{
[STAThread]
private static string token;
static void Main()
{
[...]
}
}
}
The problem is that the variable token is not working/won’t compile. I guess the error is pretty easy to spot, but I’ve tried any versions of static, public static and using functions (setters and getters) to do the work, but nothing works. I found this: Global variable in a static method , but then I had to remove [STAThread] which I have no clue what even does, so I’d rather cross this problem another way.
The source is auto-setup when I created a new project in C# 2012.
To clearify: How can I use public variables in a static class like this without having to remove STAThread?
[stathread] is an attribute and relates to the code directly below it – put it back above the main function where it was originally and put your variable above it and you’ll be fine
and you are correct that you need to declare you variable with the static keyword as you suggested