Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Symbols. 2 Identifiers Syntax Identifier = (letter | '_' | {letter | digit | '_'}. Unicode! Case-sensitive can be used to treat keywords as.

Similar presentations


Presentation on theme: "1 Symbols. 2 Identifiers Syntax Identifier = (letter | '_' | {letter | digit | '_'}. Unicode! Case-sensitive can be used to treat keywords as."— Presentation transcript:

1 1 Symbols

2 2 Identifiers Syntax Identifier = (letter | '_' | '@') {letter | digit | '_'}. Unicode! Case-sensitive "@" can be used to treat keywords as identifiers -if... keyword -@if... identifier if May contain Unicode escape sequences (e.g. \u03c0 for p) Examples someName sum_of3 _10percent @whilethe identifier while pthe identifier p \u03c0the identifier p b\u0061ckthe identifier back

3 3 Keywords abstractasbaseboolbreak bytecasecatchcharchecked classconstcontinuedecimaldefault delegatedodoubleelseenum eventexplicitexternfalsefinally fixedfloatforforeachgoto ifimplicitinintinterface internalislocklongnamespace newnullobjectoperatorout overrideparamsprivateprotectedpublic readonlyrefreturnsbytesealed shortsizeofstackallocstaticstring structswitchthisthrowtrue trytypeofuintulongunchecked unsafeushortusingvirtualvoid volatilewhile 77 keywords in C# in contrast to 47 keywords in Java

4 4 Naming Conventions Casing Words are capitalized (e.g. ShowDialog) First letter in upper case, except for private or local variables, constants and fields constantsupper caseSIZE, MAX_VALUE local variableslower casei, top, sum private fieldslower casedata, lastElement public fieldsupper caseWidth, BufferLength propertiesupper caseLength, FullName enumerationupper caseRed, Blue constants methodsupper caseAdd, IndexOf typesupper caseStringBuilder (predefined types in lower case: int, string) namespacesupper caseSystem, Collections First word Names of void methods should start with a verb (e.g. GetHashCode) Other names should start with a noun (e.g. size, IndexOf, Collections) Enumeration constants or bool members may start with an adjective (Red, Empty)

5 5 Integer Numbers Syntax DecConstant = digit {digit} {IntSuffix}. HexConstant = "0x" hexDigit {hexDigit} {IntSuffix}. IntSuffix = 'u' | 'U' | 'l' | 'L'. Type without suffix: smallest type from int, uint, long, ulong suffix u, U: smallest type from uint, ulong suffix l, L: smallest type from long, ulong Examples 17int 9876543210long 17Llong 17uuint 0x3fint 0x10000long 0x3fLlong

6 6 Floating-point Numbers Syntax (simplified) RealConstant = [Digits] ["." [Digits]] [Exp] [RealSuffix]. must have at least 1 digit and either ".", Exp or RealSuffix Digits = digit {digit}. Exp = ("e" | "E") ["+" | "-"] Digits. RealSuffix = "f" | "F" | "d" | "D" | "m" | "M". Type without suffix: double suffix f, F: float suffix d, D: double suffix m, M: decimal Examples 3.14double 1E-2double.1double 10ffloat

7 7 Character Constants and Strings Syntax CharConstant = ' char '. StringConstant = " {char} ". char can be Any character except closing quote, end-of-line or \ Escape sequences \'' \"" \\\ \00x0000 \a0x0007 (alert) \b0x0008 (backspace) \f0x000c (form feed) \n0x000a (new line) \r0x000d (carriage return) \t0x0009 (horizontal tab) \v0x000b (vertical tab) Unicode- or hexadecimal escape sequences \u0061a \x0061a

8 8 Character Constants and Strings (cont.) Examples for escape sequences in strings "file \"C:\\sample.txt\"" file "C:\sample.txt" "file \x0022C:\u005csample.txt\x0022" If the string is preceded by a @ the \ is not interpreted as a escape character any " must be doubled the string may span several lines Example @"file file ""C:\sample.txt""""C:\sample.txt"

9 9 Comments Single-line comments // a comment Delimited comments /* a comment */ must not be nested Documentation comments /// a documentation comment


Download ppt "1 Symbols. 2 Identifiers Syntax Identifier = (letter | '_' | {letter | digit | '_'}. Unicode! Case-sensitive can be used to treat keywords as."

Similar presentations


Ads by Google