Net-informations.com
SiteMap  | About    

Literals and Constants in C#

Literal is a source code representation of a value, i.e. it is a value that has been hard-coded directly into your source.

Example

x is a variable, and 100 is a literal.

Type of literals in C# are:

  1. Boolean Literal
  2. Integer Literal
  3. Real Literal
  4. Character Literal
  5. String Literal
  6. Null Literal

Boolean Literal

There are two Boolean literal values: true and false.

Example

Integer Literal

Integer literals are used to write values of types int, uint, long, and ulong. Integer literals have two possible forms: decimal and hexadecimal.

Example

Real Literal

Real literals are used to write values of types float, double, and decimal.

Example

Character Literal

A character literal represents a single character, and usually consists of a character in quotes, as in 'a'.

Example

C# Character Literal

String Literal

C# supports two forms of string literals: regular string literals and verbatim string literals . A regular string literal consists of zero or more characters enclosed in double quotes, as in "string", and may include both simple escape sequences (such as \t for the tab character) and hexadecimal and Unicode escape sequences. A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. They can store characters or escape sequences. A simple example is @"string".

Example

Null Literal

Null Literal is literal that denotes null type. Moreover, null can fit to any reference-type . and hence is a very good example for polymorphism.

Example

Constants

Constants are values which are fixed and cannot be changed anytime during program execution. They can be of any data type.









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.