1 / 9

Symbols

Symbols. 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

Download Presentation

Symbols

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Symbols

  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 • @while the identifier while • p the identifier p • \u03c0 the identifier p • b\u0061ck the identifier back

  3. Keywords abstract as base bool breakbyte case catch char checkedclass const continue decimal defaultdelegate do double else enumevent explicit extern false finallyfixed float for foreach gotoif implicit in int interfaceinternal is lock long namespacenew null object operator outoverride params private protected publicreadonly ref return sbyte sealedshort sizeof stackalloc static stringstruct switch this throw truetry typeof uint ulong uncheckedunsafe ushort using virtual voidvolatile while 77 keywords in C# in contrast to 47 keywords in Java

  4. Naming Conventions Casing • Words are capitalized (e.g. ShowDialog) • First letter in upper case, except for private or local variables, constants and fields constants upper case SIZE, MAX_VALUE local variables lower case i, top, sum private fields lower case data, lastElement public fields upper case Width, BufferLength properties upper case Length, FullName enumeration upper case Red, Blue constants methods upper case Add, IndexOf types upper case StringBuilder (predefined types in lower case: int, string) namespaces upper case System, 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. 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 17 int 9876543210 long 17L long 17u uint 0x3f int 0x10000 long 0x3fL long

  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.14 double 1E-2 double .1 double 10f float

  7. Character Constants and Strings Syntax CharConstant = ' char '. StringConstant = " {char} ". char can be Any character except closing quote, end-of-line or \ Escape sequences \' ' \" " \\ \ \0 0x0000 \a 0x0007 (alert) \b 0x0008 (backspace) \f 0x000c (form feed) \n 0x000a (new line) \r 0x000d (carriage return) \t 0x0009 (horizontal tab) \v 0x000b (vertical tab) Unicode- or hexadecimal escape sequences \u0061 a \x0061 a

  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. Comments Single-line comments // a comment Delimited comments /* a comment */ must not be nested Documentation comments /// a documentation comment

More Related