C# field initialization
In this chapter you will learn:
Description
Field initialization is optional.
An uninitialized field has a default value (0, \0, null, false). Field initializers run before constructors:
public int Age = 10;
Multiple fields
For convenience, you may declare multiple fields of the same type in a comma-separated list.
This is a convenient way for all the fields to share the same attributes and field modifiers.
For example:
static readonly int field1 = 8,
field2 = 1;
Next chapter...
What you will learn in the next chapter:
- What is a constant
- How to create a constant field
- Example for defining a constant field
- Local Constants
C# class field
C# Field default value
C# Read only field
C# Static Fields
C# Field default value
C# field initialization
C# ConstantC# Read only field
C# Static Fields