Static vs. Instance Properties

A typical property declared in a class is an instance property, meaning that you have a copy of that property’s value for each instance of the class.
You can also define static properties, which are properties that have a single value for the entire class, regardless of the number of instances of the class that exist.
1
2
3
4
5
6
7
8
public class Dog
{
    // An instance property--one copy for each dog
    public string Name { get; set; }
 
    // A static property--one copy for all dogs
    public static string Creed { get; set; }
}
You can read and write a static property even if no instances of the class exist.  You use the class’ name to reference a static property.


1
2
3
4
5
6
7
8
9
// Writing an instance property  (Name)
Dog kirby = new Dog();
kirby.Name = "Kirby";
 
Dog jack = new Dog();
jack.Name = "Jack";
 
// Write a static property
Dog.Creed = "We are best friends to humans.";