Initializing arrays

Top  Previous  Next

What is translated > Types > Arrays > Initializing arrays

 

The initialization of arrays in Delphi and C# looks very similar. For example the initialization of an array of TStyleRecord's:

 

type

TStyleRecord = record

  Name    : string;

  Color   : TColor;

  Style   : TFontStyles;

end;

TStylesArray = Array[0 .. 2] Of TStyleRecord;

 

 

const  

 

DefaultStyles : TStylesArray = (

 (Name : 'tnone';    Color : clBlack;  Style :  []),

 (Name : 'tstring';  Color : clMaroon; Style :  []),

 (Name : 'tcomment'; Color : clNavy;   Style :  [fsItalic])

);

 

->

 

public struct TStyleRecord

{

  public string Name;

  public int /*-0x7FFFFFFF - 1..0x7FFFFFFF*/ Color;

  public TSet Style;

  public static TStyleRecord CreateRecord(){return new TStyleRecord();}

};

 

public static readonly TStyleRecord[] DefaultStyles = {new TStyleRecord{Name="tnone", Color=claBlack, Style=new TSet()}, 

new TStyleRecord{Name="tstring", Color=claMaroon, Style=new TSet()}, 

new TStyleRecord{Name="tcomment", Color=claNavy, Style=new TSet() << (int) TArrays_FontStyle.fsaItalic}};

 

 

 

 

 



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content