C#: Constants

A few notes about constants in C#:

  1. Once a constant has been assigned a value, you can’t change it’s value or you’ll receive a compile error.
  2. Constants may not be used as return values.
  3. The value assigned to a constant must be known at compile time.
  4. Constant fields are static and thus need to be prefixed with the type name. However if referencing a constant within the current type or member, you don’t need to prefix it with the type name.

Leave a Reply

Your email address will not be published. Required fields are marked *