Get to know Fields - CSharp Custom Type

CSharp examples for Custom Type:Field

Introduction

A field is a variable that is a member of a class or struct. For example:

class Animal
{
 string name;
 public int Age = 10;
}

Fields allow the following modifiers:

Static modifier static
Access modifiers public internal private protected
Inheritance modifier new
Unsafe code modifier unsafe
Read-only modifierreadonly
Threading modifier volatile

The readonly modifier

The readonly modifier prevents a field from being modified after construction.

A read-only field can be assigned only in its declaration or within the enclosing type's constructor.


Related Tutorials