Skip to main content

Posts

Showing posts with the label Static

C# 2 - Static Members

In C# 2 there was a new addition in the functionality called static classes and members . When i say "members", i am referring to methods, properties, events and so on. I have a strong opinion about this modifier which i will share with you along the article, but let's start by looking at what "static" means. Take this code as example: Above we can see that we define two properties and one is static. In the main method we then create an instance of Person and set the normal property ( Name ). Now notice the Person.NumberOfBrains  assignment. This is the static property we created in the class. Notice that the access is made at class level , instead of instance level.  This means that there will only be one NumberOfBrains  value throughout all Person instances, but there will be a Name  value per each instance  of Person . Of course, the example is not the best, but you get the idea. Static applies when all  instances share the same value. There are so...