[WEBINAR] Bulletproof: How Today's Business Leaders Stay on Top


Definition - What does Field mean?

A field, in C#, is a member of a class or an object of any type that represents a memory location for storing a value.

Fields are used to store data that must be accessible to multiple methods of a class and available throughout the lifetime of an object. Fields enable a class or struct to encapsulate the data with options to specify its accessibility at multiple levels.

In general, a field is used for defining a variable in a class with accessibility as private or protected. A field that needs to be exposed anywhere outside of the class can be encapsulated as a public method, property or indexer.

A field is also known as a class-level variable or member variable.

Techopedia explains Field

A field has to be declared in a type (class or struct) with its data type and an identifier that names the member. It can also be specified with attributes and modifiers such as new, access modifier (public, private, protected, internal), static, read-only and volatile during its declaration. It may also be assigned an initial value.

A field can be of static or instance type. A static field is not associated with any instance of a type and is shared among all instances of the type. An instance field is associated with an instance of a type such that every instance of a type has its own set of all the instance fields of a class.

For example, the personal details of an Employee class like name, designation, etc. can be stored as instance fields to store the values of each Employee object.

A read-only field can be assigned only during declaration or in an instance or static constructor of that class.

A field differs from a local variable in that the former can be accessed by more than one method and can be used outside the scope of a single method, while the latter is used within the method itself.

A field can be protected by a property that allows reading and writing (after validation) a field. Property also allows for changing the internal implementation of data represented as a field without breaking the existing code.

This definition was written in the context of C#
Share this:

Connect with us

Email Newsletter

Join thousands of others with our weekly newsletter

The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
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.