user1590636
user1590636

Reputation: 1194

static variable inside a static class and a static variable inside a non static class

what is the difference between a static variable inside a static class and a static variable inside a non static class?

ex:

public static class GT
{
   public static readonly string x;
}


public class GT
{
   public static readonly string x;
}

Upvotes: 1

Views: 152

Answers (1)

Simon Whitehead
Simon Whitehead

Reputation: 65079

There is no difference when you're talking about the actual variables inside the class. A static variable inside a static class is the same as a static variable inside a non static class.

On the other hand.. if you're talking about the classes themselves, then the static class cannot contain instance variables or methods.. it doesn't make sense.. since you cannot instantiate an instance of a static class yourself.

Upvotes: 3

Related Questions