Friday 9 December 2016

Static in C#

You are relaxing on a tropical island. No one else is there. A bird flies by in the sky. The island is static in memory—only one instance exists.

Many locations exist in computer memory. A static thing stands alone. It occupies just one location. Static is used on methods, classes and constructors.

Static denotes things that are singular. They are part of no instance. Static often improves performance, but makes programs less flexible.


Static methods. These are called with the type name. No instance is required—this makes them slightly faster. Static methods can be public or private.

Static methods use the static keyword, usually as the first keyword or the second keyword after public.
Warning:A static method cannot access non-static class level members. It has no "this" pointer.
Instance:An instance method can access those members, but must be called through an instantiated object. This adds indirection.













Output :

No comments: