Constants
Literals/constants are used to represent fixed values which can't be altered later in the code.
1. Integer literals
Interger literals are numeric literals. Below are the examples of various types of literals
2. Float point literals
Float point literals are also numeric literals but has either a fractional form or an exponent form.
3. Boolean literals
There are two Boolean literals which are part of standard C# keywords −
-
true value representing true.
-
false value representing false
4. Character literals
Character literals are represented with in single quotes. For example, a
, 1
etc. A character literal can be a simple character (e.g., 'a'), an escape sequence (e.g., '\n'), or a universal character (e.g., '\u02C0').
Escape sequence | Description |
---|---|
\n | New line |
\r | Carriage Return |
? | Question mark |
\t | Horizontal tab |
\v | Vertical tab |
\f | Form feed |
\ | Backslash |
' | Single quotation |
" | Double quotation |
\0 | Null character |
? | ? Question mark |
\b | Back space |
\a | alert or bell |
5. String literals
String literals are represented with in double quotes. String literals contains series of characters which can be plain characters, escape sequence or a universal character.
How to define constants
- Using Const