Chapter 7. Constants and Fields
In this chapter:
In this chapter, I’ll show you how to add data members to a type. Specifically, we’ll look at constants and fields.
Constants
A constant is a symbol that has a
never-changing value. When defining a constant symbol, its value must be
determinable at compile time. The compiler then saves the constant’s
value in the assembly’s metadata. This means that you can define a constant only
for types that your compiler considers primitive types. In C#, the
following types are primitives and can be used to define constants:
Boolean, Char,
Byte, SByte,
Int16, UInt16,
Int32, UInt32,
Int64, UInt64,
Single, Double,
Decimal, and String. However, C# also allows you to define a constant variable of a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access