Static keyword in C#
Below is the link for Extension methods. https://youtu.be/upYtgw-jMHQ Static Keyword in C# *) Static keyword can be applied on class, method, property, constructor, event and once static is applied, then member starts belonging to class itself rather than specific object of that class. *) static class contains only static members. *) static members are invoked using name of the class and non-static members are invoked using instance of the class. *) An instance member(non-static) belongs to specific instance of a class. If we create multiple objects of a class we will have multiple sets of instance members in the memory, where as there will ever be only one copy of a static member, no matter how many instances of a class are created. *) If something is going to be common for all the classes then we should opt for static field for example value of PI=3.141 *) Static classes are sealed hence it cannot be inherited. *) A static class can be used to define extension methods that can be used to extend the functionality of existing classes without the need to modify them. Static constructor :- 1) Static constructors are used to initialize the static fields in a class 2) in order to create a static constructor, we just have to use static keyword in constructor and it becomes static constructor 3) Static constructor is called only once irrespective of number of objectes we create for a class. 4) We can create only one static constructor and it would be parameterless. The runtime automatically calls the static constructor before the first instance is created or any static member is accessed.You cannot call it manually. Static constructors do not have access modifiers like public, private, etc. They are implicitly private because they cannot be called outside the class.
Download
0 formatsNo download links available.