diff options
author | Max Yankov <golergka@gmail.com> | 2013-08-17 22:45:01 +0200 |
---|---|---|
committer | Max Yankov <golergka@gmail.com> | 2013-08-17 22:45:01 +0200 |
commit | b488745fc646b16df4ef87ddb746af596ea6588f (patch) | |
tree | 5bb45bcf8da8dbea27a1cbc5baad3359da3e8637 | |
parent | 0312c061b292985a5d849253480b0a8e5eafb332 (diff) |
Static field
-rw-r--r-- | csharp.html.markdown | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/csharp.html.markdown b/csharp.html.markdown index b113b6d3..3de1eb66 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -403,7 +403,12 @@ namespace Learning private int _speed; // Private: Only accessible from within the class protected int gear; // Protected: Accessible from the class and subclasses internal int wheels; // Internal: Accessible from within the assembly - string name; // default: Only accessible from within this class + string name; // Everything is private by default: Only accessible from within this class + + // Static members belong to the type itself rather then specific object. + static public int bicyclesCreated = 0; + // You can access them without a reference to any object: + // Console.WriteLine("Bicycles created: " + Bicycle.bicyclesCreated); // readonly values are set at run time // they can only be assigned upon declaration or in a constructor @@ -417,6 +422,7 @@ namespace Learning cadence = 50; _speed = 5; name = "Bontrager"; + bicyclesCreated++; } // This is a specified constructor (it contains arguments) |