-
Notifications
You must be signed in to change notification settings - Fork 1
Const Fields
Mario Gutierrez edited this page Jan 7, 2017
·
1 revision
- A
const
field must be assigned at the time of the declaration. - A
readonly
field can be assigned at declaration or in the constructor.
const
is implicitly static.
public const int PI = 3.1415f;
readonly
is an instance variable.
public readonly DateTime INITIALIZED;
public MyBrand()
{
INITIALIZED = DateTime.Now;
}
static
can be used with readonly
, which is almost like const
public static readonly DateTime FIRST_INITIALIZATION;
static MyBrand()
{ // The difference is you can use a static constructor to initialize it.
FIRST_INITIALIZATION = DateTime.Now;
}
- Abstract Classes
- Access Modifiers
- Anonymous Methods
- Anonymous Types
- Arrays
- Attributes
- Console I/O
- Constructors
- Const Fields
- Delegates
- Enums
- Exceptions
- Extension Methods
- File IO
- Generics
- Interfaces
- Iterators
- LINQ
- Main
- Null Operators
- Parameters
- Polymorphism
- Virtual Functions
- Reflection
- Serialization
- Strings
- Value Types
- "Base" Keyword
- "Is" and "As"
- "Sealed" Keyword
- nameof expression