Explain the use of static members with example using C#.NET.- Static members are not associated with a particular instance of any class.
- They need to be qualified with the class name to be called.
- Since they are not associated with object instances, they do not have access to non-static members, it means that "this" cannot be used, which represents the current object instance.
- It is callable on a class even when no instance of the class has been created.
- Static member is always accessed by the class name, not instance name.
- Static methods and properties cannot access non-static fields and events in their containing type.
- They cannot access an instance variable of any object unless it is explicitly passed in a method parameter.
- Static members can be overloaded, but cannot overridden, because they belong to the class and not to any instance of the class.
|