Pascal for CSharp users

From Lazarus wiki
Revision as of 03:29, 30 March 2009 by Schala (talk | contribs)
Jump to navigationJump to search
  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 optionalComment}  
  #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 ProgramName; Begin End.   Note the period after End
  someType arrayVar[];   arrayVar: Array Of someType;  
  someType arrayVar[#];   arrayVar: Array[MINRANGE..MAXRANGE] Of someType;  
  null   Nil  
  abstract   Abstract  
  break   Break  
  class TheClass { }   TheClass = Class End;   Delphi OOP
  class TheClass { }   TheClass = Object End;   Turbo Pascal OOP
  class TheClass<T> { }   Generic TheClass = Class<T> End;   Generics are classes only as of 2.2.2, likely to support more in the future
  TheClass()   Constructor CtorName   Constructor name is by convention either Init or Create
  continue   Continue  
  default   Default  
  do while     Repeat Until Not   
  do while !     Repeat Until    
  enum TheEnum    TheEnum = ( MINVALUE .. MAXVALUE );    
  enum TheEnum = {MINVALUE, MAXVALUE}    TheEnum = ( MINVALUE, MAXVALUE );    
  TheEnum enumVar;     enumVar := Set Of TheEnum;    
  Subclass : BaseClass   SubClass = Class(BaseClass)  
  const   Const   for constants, not uninheritables
  for ++     For To Do  
  for --     For Downto Do    
  if()     If Then  
  if() else     If Then Else  
  using   Uses  
  interface   TheInterface = Interface  
  new primitive_type[#];   SetLength(ArrayVar, #);    
  new Class();   InstanceVar := TheClass.Create;    
  namespace Name { }   Unit Name; Interface Implementation End.   Note the period after End
  override   Override  
  private   Private  
  protected   Protected  
  public   Public  
  return   FunctionName :=  
  return   Result :=   ObjFPC or Delphi modes
  sealed    
  static   Static  
  static   Class Function  
  static   Class Procedure  
  struct TheStruct { }   TheRecord = 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  


  C# type     Pascal type     Size (bits)     Range    
  byte     Shortint   8-bit   -128 .. 127  
  short     SmallInt   16-bit   -32768 .. 32767  
  int     LongInt   32-bit   -2147483648..2147483647    
  int     Integer   32-bit   -2147483648..2147483647    
  long     Int64   64-bit   -9 223 372 036 854 775 808 .. 9 223 372 036 854 775 807    
  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