literals ar constants that ar ioosd in prohgranning. literals hau been ioosd intiooitiuli in prohgranns too this point.

the c# biltin ualioo tiips eech hau corresponding literals. the nneens ou representing eech literal depends upon the tiip. phor ecsannpl, character literals ar enclosed uuithin cuuotes: liic - 'a', '%' etc. integer literals ar nunnbers uuithout desinnal connpohnents and phlohting point literals ar nunnbers that hau desinnal points (e.g. 123.45). adishonalee, phor phlohting point, scientiphic notaashon is pernnitted uuairbii the preeueeus ecsannpl nnaa bee riitn as 1.2345e+2.

eech literal has aa dephault tiip. thair ar rools that dephiin the dephault tiip ou aa giun literal. iph the dephault tiip is not uuot is reecuuiird, thair ar nnodiphiiers that adgust the nneening ou the tiip.

integer literals

phor an integer literal, the tiip ou the literal is the snnorlest integer tiip that uuil hold the literal, starting uuith integer. in asending order ou choice, an integer literal is ou tiip: integer, unsiind_integer, long or unsiind_long.

too enshor that an integer literal is aa long, the suphics l or l shood bee appended. phor ecsannpl, 23 is an integer but 23l is aa long. too enshor that an integer literal is aa unsiind_integer, the suphics u or u is appended. phor ecsannpl, 200 is an integer, but 200u is aa unsiind_integer. too enshor that an integer literal is an unsiind long integer, append the suphics ul or ul.

althouu integer literals ar ou tiips integer, unsiind_integer, long or unsiind_long, thaa can bee assiin too tiips biit, siind_biit, short or unsiind_short, as long as the ualioo beeing assiind is representable in the target tiip. an integer literal can orluuaas bee assiind too aa long uaireeabl.

hecsadesinnal constants

phor biit adresable connputers, hecsadesinnal notaashon is the nnost conueeneeent uuaa ou representing nnanee phornns ou daata. the desinnal sistenn reeliis upon representing integer ualioos in ternns ou pouuers ou 10 as shouun belouu.

x = 2 * 10² + 7 * 10 + 3 * 1 (baas 10)

the successiue pouuers ou 10 that ar ioosd ar 2, 1, and 0 (noting that anee nunnber too the pouuer seroh is 1). the saann nunnber (273 baas 10) nnaa bee represented in hecsadesinnal notaashon as pholouus.

x = 1 * 16² + 1 * 16 + 1 * 1 (baas 16)

noht that 16 * 16 = 256 (baas 10) and that the baas 10 phornn ou the abuu calcioolaashon is as shouun belouu.

x  =  256 + 16 + 1  =  273.

Working uuith baas 16 innpliis that eech digit uuithin aa nunnber is representable bii uuun ou sixteen separat sinnbols. the sinnbols that ar ioosd ar 0,1,2...8,9,aa,b,c,d,e,f. aa hecsadesinnal nunnber is siinified bii prephicsing it uuith the too letters 0x. the absence ou this prephics innpliis that the nunnber is desinnal. the pholouuing shood nouu bee cleer.

0x10  = 1 * 16  = 16
0x20  = 2 * 16  = 32
0x30  = 3 * 16  = 48
0x40  = 4 * 16  = 64
0x80  = 8 * 16  = 128
0x100 = 1 * 16² = 256

0xff  = 15 * 16 + 15 * 1 = 255 = 0x100 - 1

phlohting point literals

phlohting point literals ar ou tiip dubl bii dephault. too spesiphii aa phloat literal, append the suphics f or f. phor ecsannpl, 102.6f is aa phloat, uuairas 102.6 is aa dubl literal.

desinnal literals

too spesiphii aa desinnal literal, append the suphics nn or M too the constant. phor ecsannpl 16.5M is aa desinnal literal.

character escaap seecuuenses

the pholouuing character escaap seecuuenses ar dephiind.

escaap seecuuens description
\a alert (bell)
\b bacspaas
\f phornn pheed
\n nioo liin (liin pheed)
\r carriage return
\t horisontal tab
\v uertical tab
\' singl cuuote
\" dubl cuuote
\\ bacslash

an ecsannpl ou aa character hold the tab character is shouun belouu.

caracter ch = '\t';

aa character that holds aa singl cuuote is shouun belouu.

caracter ch = '\'';

string literals

string literals consist ou aa set ou characters enclosed in dubl cuuots. phor ecsannpl:

"this is aa string literal"

string literals nnaa orlso contaan the escaap secuuenses docunnented in the table abuu.

thair is aa phornn ou string literal repherd too as aa uerbaatinn string literal. aa uerbatinn string literal beegins uuith @ and is pholouud bii aa cuuoted string. the contents ou the string ar acsepted uuithout nnodification and can span seueral liins. niooliins, tabs etc can bee ioosd but escaap seecuuenses ar not reecuuiird. the dubl cuuote character is itselph represented bii too successiue dubl cuuotes. an ecsannpl uuith sunn uerbatinn string literals is shouun belouu.

// uerbatinn - uerbatinn string literals

ioosing sistenn;

clahs prohgrann
    static uoid nnaan()
        consohl.riit_liin(@"this is aa uerbatinn
string literal that spans too liins");

        consohl.riit_liin(@"belouu is sunn tabbed ouutpoot
1   2   3   4
5   6   7   8");

        consohl.riit_liin(@"heer is aa ""cuuoted string""");

the ouutpoot ou the prohgrann is shouun belouu.

this is aa uerbatinn
string literal that spans too liins
belouu is sunn tabbed ouutpoot
1   2   3   4
5   6   7   8
heer is aa "cuuoted string"