C# Literals

C# literals are different data types' values which are used in C# code directly.

The following is the summary table which defines all the literals in C#.

LiteralsSub ItemsDescriptionExamples
Boolean LiteralsOnly 2 literals: true, false bool isReturned = false;
Integer literalsintint literals, no suffix.int i = -0xcd;
uintuint literals, which can be suffixed by U or u.uint i = 123;
longlong literals, which can be suffixed by L or l.long i = -0x12abL;
ulongulong literals, which can be suffixed by U, u, L, l, UL, Ul, uL, ul, LU, Lu, lU, or lu.ulong i = 0x56f7UL;
Real literalsfloatfloat literals, which can be suffixed by F or f.float ff = -12.55f;
doubledouble literals, which can be suffixed by D or d.double dd = 2.5e-5D;
decimaldecimal literals, which can be suffixed by M or m.decimal mm = 1234e5M;
Character literalsSingle characterchar c = 'B';
Simple character escape sequencechar c = '\n';
Unicode character escape sequencechar c = '\u0062';
Hexadecimal character escape sequencechar c = '\x62';
String literalsRegular string literalsstring s = "abc\n\"def\"";
Verbatim string literalsstring s = @"abc""def""";
null literalsOnly null value: we'll learn it in details after class introduction.string s = null;

You can click each literal link above to go to detailed page.