简体   繁体   中英

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;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM