Difference between revisions of "Pascal for CSharp users"
From Free Pascal wiki
Jump to navigationJump to search(19 intermediate revisions by 10 users not shown) | |||
Line 1: | Line 1: | ||
− | {| | + | ==Syntax Comparison== |
− | ! | + | {| class="wikitable" |
− | ! | + | ! C# !! [[Pascal]] !! Additional comments |
− | ! | ||
|- | |- | ||
| { | | { | ||
Line 227: | Line 226: | ||
| [[For]] [[Downto]] [[Do]] | | [[For]] [[Downto]] [[Do]] | ||
| | | | ||
+ | |- | ||
+ | | foreach( in ) | ||
+ | | [[For]] [[In]] | ||
+ | | [[for-in_loop|For .. in loop]] | ||
|- | |- | ||
| if() | | if() | ||
Line 255: | Line 258: | ||
| [[Unit]] ; [[Interface]] [[Implementation]] [[End]]. | | [[Unit]] ; [[Interface]] [[Implementation]] [[End]]. | ||
| Note the period after End | | Note the period after End | ||
+ | |- | ||
+ | | out | ||
+ | | [[Out]] | ||
+ | | | ||
|- | |- | ||
| override | | override | ||
Line 270: | Line 277: | ||
| public | | public | ||
| [[Public]] | | [[Public]] | ||
+ | | | ||
+ | |- | ||
+ | | ref | ||
+ | | [[Variable_parameter|Var]] | ||
| | | | ||
|- | |- | ||
Line 281: | Line 292: | ||
|- | |- | ||
| sealed | | sealed | ||
− | | | + | | sealed |
− | | | + | | starting from fpc 2.5.1 |
|- | |- | ||
| static | | static | ||
Line 342: | Line 353: | ||
| while | | while | ||
| [[While]] [[Do]] | | [[While]] [[Do]] | ||
+ | | | ||
+ | |- | ||
+ | | | ||
+ | | [[Asm]] [[End]]; | ||
| | | | ||
|} | |} | ||
− | + | ==Types Comparison== | |
− | {| | + | {| class="wikitable" |
− | ! | + | ! C# type !! [[Pascal]] [[Data_type|type]] !! Size (bits) !! Range !! |
− | ! | ||
− | ! | ||
− | ! | ||
− | ! | ||
|- | |- | ||
− | | | + | | sbyte |
− | | [[Shortint]] | + | | [[Shortint|ShortInt]] |
| 8-bit | | 8-bit | ||
| -128 .. 127 | | -128 .. 127 | ||
| | | | ||
|- | |- | ||
− | | | + | | byte |
− | | [[ | + | | [[Byte]] |
| 8-bit | | 8-bit | ||
| 0 .. 255 | | 0 .. 255 | ||
Line 366: | Line 377: | ||
|- | |- | ||
| short | | short | ||
− | | [[SmallInt]] | + | | [[Smallint|SmallInt]] |
| 16-bit | | 16-bit | ||
| -32768 .. 32767 | | -32768 .. 32767 | ||
Line 372: | Line 383: | ||
| ushort | | ushort | ||
| [[Word]] | | [[Word]] | ||
− | | | + | | 16-bit |
− | | | + | | 0 .. 65535 |
| | | | ||
|- | |- | ||
| int | | int | ||
− | | [[LongInt]] | + | | [[Longint|LongInt]] |
| 32-bit | | 32-bit | ||
| -2147483648..2147483647 | | -2147483648..2147483647 | ||
Line 383: | Line 394: | ||
|- | |- | ||
| uint | | uint | ||
− | | [[LongWord]] | + | | [[Longword|LongWord]] |
| 32-bit | | 32-bit | ||
| 0..4294967295 | | 0..4294967295 | ||
Line 426: | Line 437: | ||
| string | | string | ||
| [[String]] | | [[String]] | ||
+ | | | ||
+ | | | ||
+ | |- | ||
+ | | datetime | ||
+ | | [[TDateTime]] | ||
| | | | ||
| | | | ||
Line 431: | Line 447: | ||
|- | |- | ||
|} | |} | ||
+ | |||
+ | ==C# Language Features Not available in Pascal== | ||
+ | * automatic memory management while - not available, except for reference counted types: strings (except for shortstrings), dynamic arrays | ||
+ | * lambda functions | ||
+ | * serialization (as syntax language) - you'd need to use explicit functions/procedures to convert to/from data structures | ||
+ | * LINQ | ||
+ | |||
+ | ==FPC Language Features not available in C #== | ||
+ | * [[Assembler]], [[Assembly language]] | ||
+ | * Case-insensitive | ||
+ | [[Category:FPC]] | ||
+ | [[Category:Pascal]] | ||
+ | [[Category:C-Sharp]] |
Latest revision as of 14:17, 6 February 2023
Syntax Comparison
C# | Pascal | Additional comments |
---|---|---|
{ | Begin | |
} | End | |
= | := | Becomes |
== | = | Equal |
/ | / | Division (or sometimes div) |
% | Mod | Modulo operation |
! | Not | |
!= | <> | Not equal |
&& | And | |
|| | Or | |
^ | Xor | |
>> | Shr | bit shift right |
<< | Shl | bit shift left |
++ | Inc | |
-- | Dec | |
/* | { | Comment start |
/* | (* | Comment start |
*/ | } | Comment end |
*/ | *) | Comment end |
// | // | End of line comment (only one line comment) |
#define | {$Define } | |
#define | {$SetC } | Mac Pascal |
#elif | ||
#else | {$Else} | |
#else | {$ElseC } | Mac Pascal |
#endif | {$EndIf } | |
#endregion | ||
#error | {$Fatal } | |
#if | {$If } | |
#if | {$IfC } | Mac Pascal |
#ifdef | {$IfDef } | |
#ifndef | {$IfNDef } | |
#pragma | {$IfOpt } | |
#region | ||
#undef | {$Undef } | |
#warning | {$Hint } | |
public static void Main(string[] args) { } | Program ; Begin End. | Note the period after End |
[]; | : Array Of ; | |
[#]; | : Array[#..#] Of ; | |
null | Nil | |
abstract | Abstract | |
break | Break | |
class { } | = Class End; | Delphi OOP |
class { } | = Object End; | Turbo Pascal OOP |
class <T> { } | Generic = Class<T> End; | Generics are classes only as of 2.2.2, likely to support more in the future |
Class() | Constructor | Constructor name is by convention either Init or Create |
continue | Continue | |
do while | Repeat Until Not | |
do while ! | Repeat Until | |
enum { } | = (# .. #); | |
enum = { = #, } | = ( = #, ); | |
TheEnum enumVar; | := Set Of ; | |
class : | = Class(TObject) | |
const | Const | for constants, not uninheritables |
for( = ; ; ++) | For To Do | |
for( = ; ; --) | For Downto Do | |
foreach( in ) | For In | For .. in loop |
if() | If Then | |
if() else | If Then Else | |
using | Uses | |
interface { } | = Interface(IInterface) End; | |
new [#]; | SetLength( , #); | |
new (); | := .Create; | |
namespace Name { } | Unit ; Interface Implementation End. | Note the period after End |
out | Out | |
override | Override | |
private | Private | |
protected | Protected | |
public | Public | |
ref | Var | |
return | FunctionName := | |
return | Result := | ObjFPC or Delphi modes |
sealed | sealed | starting from fpc 2.5.1 |
static | Static | |
static | Class Function | |
static | Class Procedure | |
struct { } | = Record End; | |
base | Inherited | Parent constructor call |
switch () { case: break; } | Case Of End ; | |
switch() { case: break; default: } | Case Of Else End | |
this | Self | |
try { } catch | Try except | |
try { } catch finally | Try Finally | |
unsafe | ||
virtual | Virtual | |
void | Procedure | |
volatile | ||
while | While Do | |
Asm End; |
Types Comparison
C# type | Pascal type | Size (bits) | Range | |
---|---|---|---|---|
sbyte | ShortInt | 8-bit | -128 .. 127 | |
byte | Byte | 8-bit | 0 .. 255 | |
short | SmallInt | 16-bit | -32768 .. 32767 | |
ushort | Word | 16-bit | 0 .. 65535 | |
int | LongInt | 32-bit | -2147483648..2147483647 | |
uint | LongWord | 32-bit | 0..4294967295 | |
long | Int64 | 64-bit | -9 223 372 036 854 775 808 .. 9 223 372 036 854 775 807 | |
ulong | QWord | 64-bit | 0 .. 18 446 744 073 709 551 615 | |
float | Single | 32-bit | 1.5E-45 .. 3.4E+38 | |
double | Double | 64-bit | 5.0E-324 .. 1.7E+308 | |
bool | Boolean | False True | ||
char | WideChar | 16-bit | ||
string | String | |||
datetime | TDateTime |
C# Language Features Not available in Pascal
- automatic memory management while - not available, except for reference counted types: strings (except for shortstrings), dynamic arrays
- lambda functions
- serialization (as syntax language) - you'd need to use explicit functions/procedures to convert to/from data structures
- LINQ
FPC Language Features not available in C #
- Assembler, Assembly language
- Case-insensitive