Static Members
Understand the meaning of the static keyword.
We'll cover the following...
Static vs. instance members
We’ve used the static
keyword regularly throughout this course, but haven’t really talked about what that means.
Consider the following class
:
class Person
{
public int Age { get; set; }
public string Name { get; set; }
}
To use this class
, we have to create its instance:
var person1 = new Person();
person1.Age = 41;
person1.Name = "John Doe";
var person2 = new Person();
person2.Age = 38;
person2.Age = "Jim Terry";
We now have two instances of the Person
class
, and each instance has its own copy of the Age
...