Pascal for CSharp users: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Pascal for CSharp users
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Syntax Comparison | |
| 2 | + | ||
| 3 | + | | C# | [[Pascal]] | Additional comments | | |
| 4 | + | |----|----|----| | |
| 5 | + | | { | [[Begin]] | | | |
| 6 | + | | } | [[End]] | | | |
| 7 | + | | = | := | [[Becomes]] | | |
| 8 | + | | == | = | [[Equal]] | | |
| 9 | + | | / | / | [[Slash|Division]] (or sometimes [[Div|div]]) | | |
| 10 | + | | % | [[Mod]] | **Mod**ulo operation | | |
| 11 | + | | ! | [[Not]] | | | |
| 12 | + | | != | \<\> | [[Not equal]] | | |
| 13 | + | | && | [[And]] | | | |
| 14 | + | | \<nowiki\> | | [[Or]] | | |
| 15 | + | | ^ | [[Xor]] | | | |
| 16 | + | | \>\> | [[Shr]] | bit **sh**ift **r**ight | | |
| 17 | + | | \<\< | [[Shl]] | bit **sh**ift **l**eft | | |
| 18 | + | | ++ | [[Inc]] | | | |
| 19 | + | | -- | [[Dec]] | | | |
| 20 | + | | /* | { | [[Comments|Comment]] start | | |
| 21 | + | | /* | (* | [[Comments|Comment]] start | | |
| 22 | + | | */ | } | Comment end | | |
| 23 | + | | */ | *) | Comment end | | |
| 24 | + | | // | // | End of line comment (only one line comment) | | |
| 25 | + | | \#define | {\$Define } | | | |
| 26 | + | | \#define | {\$SetC } | Mac Pascal | | |
| 27 | + | | \#elif | | | | |
| 28 | + | | \#else | {\$Else} | | | |
| 29 | + | | \#else | {\$ElseC } | Mac Pascal | | |
| 30 | + | | \#endif | {\$EndIf } | | | |
| 31 | + | | \#endregion | | | | |
| 32 | + | | \#error | {\$Fatal } | | | |
| 33 | + | | \#if | {\$If } | | | |
| 34 | + | | \#if | {\$IfC } | Mac Pascal | | |
| 35 | + | | \#ifdef | {\$IfDef } | | | |
| 36 | + | | \#ifndef | {\$IfNDef } | | | |
| 37 | + | | \#pragma | {\$IfOpt } | | | |
| 38 | + | | \#region | | | | |
| 39 | + | | \#undef | {\$Undef } | | | |
| 40 | + | | \#warning | {\$Hint } | | | |
| 41 | + | | public static void Main(string\[\] args) { } | [[Program]] ; [[Begin]] [[End]]. | Note the period after End | | |
| 42 | + | | \[\]; | : [[Array]] [[Of]] ; | | | |
| 43 | + | | \[#\]; | : [[Array]]\[#..#\] [[Of]] ; | | | |
| 44 | + | | null | [[Nil]] | | | |
| 45 | + | | abstract | [[Abstract]] | | | |
| 46 | + | | break | [[Break]] | | | |
| 47 | + | | class { } | = [[Class]] [[End]]; | Delphi OOP | | |
| 48 | + | | class { } | = [[Object]] [[End]]; | Turbo Pascal OOP | | |
| 49 | + | | class \<T\> { } | [[Generic]] = [[Class]]\<T\> [[End]]; | Generics are classes only as of 2.2.2, likely to support more in the future | | |
| 50 | + | | Class() | [[Constructor]] | Constructor name is by convention either Init or Create | | |
| 51 | + | | continue | [[Continue]] | | | |
| 52 | + | | do while | [[Repeat]] [[Until]] [[Not]] | | | |
| 53 | + | | do while ! | [[Repeat]] [[Until]] | | | |
| 54 | + | | enum { } | = (# .. \#); | | | |
| 55 | + | | enum = { = \#, } | = ( = \#, ); | | | |
| 56 | + | | TheEnum enumVar; | := [[Set]] [[Of]] ; | | | |
| 57 | + | | class : | = [[Class]](TObject) | | | |
| 58 | + | | const | [[Const]] | for constants, not uninheritables | | |
| 59 | + | | for( = ; ; ++) | [[For]] [[To]] [[Do]] | | | |
| 60 | + | | for( = ; ; --) | [[For]] [[Downto]] [[Do]] | | | |
| 61 | + | | foreach( in ) | [[For]] [[In]] | [[for-in loop|For .. in loop]] | | |
| 62 | + | | if() | [[If]] [[Then]] | | | |
| 63 | + | | if() else | [[If]] [[Then]] [[Else]] | | | |
| 64 | + | | using | [[Uses]] | | | |
| 65 | + | | interface { } | = [[Interface]](IInterface) End; | | | |
| 66 | + | | new \[#\]; | [[SetLength]]( , \#); | | | |
| 67 | + | | new (); | := .Create; | | | |
| 68 | + | | namespace Name { } | [[Unit]] ; [[Interface]] [[Implementation]] [[End]]. | Note the period after End | | |
| 69 | + | | out | [[Out]] | | | |
| 70 | + | | override | [[Override]] | | | |
| 71 | + | | private | [[Private]] | | | |
| 72 | + | | protected | [[Protected]] | | | |
| 73 | + | | public | [[Public]] | | | |
| 74 | + | | ref | [[Variable parameter|Var]] | | | |
| 75 | + | | return | FunctionName := | | | |
| 76 | + | | return | [[Result]] := | ObjFPC or Delphi modes | | |
| 77 | + | | sealed | sealed | starting from fpc 2.5.1 | | |
| 78 | + | | static | [[Static]] | | | |
| 79 | + | | static | [[Class]] [[Function]] | | | |
| 80 | + | | static | [[Class]] [[Procedure]] | | | |
| 81 | + | | struct { } | = [[Record]] [[End]]; | | | |
| 82 | + | | base | [[Inherited]] | Parent constructor call | | |
| 83 | + | | switch () { case: break; } | [[Case]] [[Of]] [[End]] ; | | | |
| 84 | + | | switch() { case: break; default: } | [[Case]] [[Of]] [[Else]] [[End]] | | | |
| 85 | + | | this | [[Self]] | | | |
| 86 | + | | try { } catch | [[Try]] [[except]] | | | |
| 87 | + | | try { } catch finally | [[Try]] [[Finally]] | | | |
| 88 | + | | unsafe | | | | |
| 89 | + | | virtual | [[Virtual]] | | | |
| 90 | + | | void | [[Procedure]] | | | |
| 91 | + | | volatile | | | | |
| 92 | + | | while | [[While]] [[Do]] | | | |
| 93 | + | | | [[Asm]] [[End]]; | | | |
| 94 | + | ||
| 95 | + | ## Types Comparison | |
| 96 | + | ||
| 97 | + | | C# type | [[Pascal]] [[Data type|type]] | Size (bits) | Range | | | |
| 98 | + | |----|----|----|----|----| | |
| 99 | + | | sbyte | [[Shortint|ShortInt]] | 8-bit | -128 .. 127 | | | |
| 100 | + | | byte | [[Byte]] | 8-bit | 0 .. 255 | | | |
| 101 | + | | short | [[Smallint|SmallInt]] | 16-bit | -32768 .. 32767 | | | |
| 102 | + | | ushort | [[Word]] | 16-bit | 0 .. 65535 | | | |
| 103 | + | | int | [[Longint|LongInt]] | 32-bit | -2147483648..2147483647 | | | |
| 104 | + | | uint | [[Longword|LongWord]] | 32-bit | 0..4294967295 | | | |
| 105 | + | | long | [[Int64]] | 64-bit | -9 223 372 036 854 775 808 .. 9 223 372 036 854 775 807 | | | |
| 106 | + | | ulong | [[QWord]] | 64-bit | 0 .. 18 446 744 073 709 551 615 | | | |
| 107 | + | | float | [[Single]] | 32-bit | 1.5E-45 .. 3.4E+38 | | | |
| 108 | + | | double | [[Double]] | 64-bit | 5.0E-324 .. 1.7E+308 | | | |
| 109 | + | | bool | [[Boolean]] | | [[False]] [[True]] | | | |
| 110 | + | | char | [[WideChar]] | 16-bit | | | | |
| 111 | + | | string | [[String]] | | | | | |
| 112 | + | | datetime | [[TDateTime]] | | | | | |
| 113 | + | | | | | | | | |
| 114 | + | | | | | | | | |
| 115 | + | ||
| 116 | + | ## C# Language Features Not available in Pascal | |
| 117 | + | ||
| 118 | + | - automatic memory management while - not available, except for reference counted types: strings (except for shortstrings), dynamic arrays | |
| 119 | + | - lambda functions | |
| 120 | + | - serialization (as syntax language) - you'd need to use explicit functions/procedures to convert to/from data structures | |
| 121 | + | - LINQ | |
| 122 | + | ||
| 123 | + | ## FPC Language Features not available in C \# | |
| 124 | + | ||
| 125 | + | - [[Assembler]], [[Assembly language]] | |
| 126 | + | - Case-insensitive | |
| 127 | + | ||
| 128 | + | --- | |
| 129 | + | *From the Free Pascal wiki, page "Pascal for CSharp users", as it stood on 2023-02-06 after a change by Thaddy, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 130 | + | Category: C-Sharp | |
| 131 | + | Category: FPC | |
| 132 | + | Category: Pascal |
