Variant parts in records

Top  Previous  Next

What is translated > Types > Records, Classes, Interfaces > Record > Variant parts in records


C# structures cannot have variant parts as Delphi records can have. However by means of the StructLayout(LayoutKind.Explicit) and FieldOffset attributes, the behavior can be reproduced.



  TRect = packed record

    case Integer of

      0: (Left, Top, Right, Bottom: Longint);

      1: (TopLeft, BottomRight: TPoint);






public struct TRect


  /*# 0*/


  public int Left;


  public int Top;


  public int Right;


  public int Bottom;

  /*# 1*/


  public TPoint TopLeft;


  public TPoint BottomRight;

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




This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content