ALERT

[WEBINAR] Index Insanity: How to Avoid Database Chaos

Static

Definition - What does Static mean?

Static, in C#, is a keyword that can be used to declare a member of a type so that it is specific to that type. The static modifier can be used with a class, field, method, property, operator, event or constructor.

A static member of a class can be used to keep track of the instances created and maintain common data to be shared among all instances. It can be used in helper and utility classes, which usually contain generic methods that contain abstractions of pure logic. A static constructor is used to make entries in log files, as well as in wrapper class to load the dynamic link libraries (DLLs) required to execute unmanaged code.

In general, a static modifier can be used with data and functions that do not require an instance of a class to be accessed. It is mostly used when the data and behavior of a class do not depend on object identity. The use of static classes and members improves code efficiency.

Techopedia explains Static

A static member can only be referenced through the type name and not through an instance of the type. Static cannot be used with a destructor, indexer or any type other than class.

Unlike an instance field, which has a separate copy for each instance of a class, a static field (or variable) is shared by all instances of a class. A static method can be overloaded but not overridden. It cannot access non-static members. Because a static method is not called with a reference to an instance, it is faster to invoke a static method on the call stack than an instance method.

A static class can only include static members. It cannot be instantiated at run time and cannot be inherited. It has its lifetime as that of the application in which it resides. A static constructor does not have parameters and access modifiers. It is invoked automatically before the creation of the first instance or the reference to any static member.

For example, a static class, TemperatureConverter, can be used to convert temperature from Celsius to Fahrenheit and vice versa by providing two methods that contain the code for conversion.

The use of a static modifier has its own limitations that include lack of thread safety, encapsulation and maintainability.

This definition was written in the context of C#

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
Tweat cdn.techopedia.com
"Techopedia" on Twitter


'@Techopedia'
Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Resources
Free Whitepaper: The Path to Hybrid Cloud
Free Whitepaper: The Path to Hybrid Cloud:
The Path to Hybrid Cloud: Intelligent Bursting To Amazon Web Services & Microsoft Azure
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.