C#: static keyword

Use the static keyword for members of a type that are so common that there isn’t a need to create an instance of the type. A few notes on on static data:

  • Static members can only operate on other static members.
  • Static data is allocated once and shared among all instances of the same type.
  • A non-static method can make use of non-static and static data. Static data is available to all instances of the type.
  • If you assign a static member in a constructor, every time a new instance is created, the static member gets reset.

Leave a Reply

Your email address will not be published. Required fields are marked *