Enumerated types

Top  Previous  Next

What is translated > Types > Enumerated types

 

The explicit definition of enumeration types is easy to translate.

 

Day = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);  

->  

public enum Day {Mon,

          Tue,

          Wed,

          Thu,

          Fri,

          Sat,

          Sun };

 

 

However, an implicit definition is also possible in object Pascal within a variable declaration. It is decomposed for C# into an explicit type definition and the real declaration of the variable. The name of the type is derived from the name of the unit (...) by appending two underscores and a counter.

 

procedure foo;

var

 Day : (Mon, Tue, Wed, Thu, Fri, Sat, Sun);

begin end;

 

->

 

public enum test__0 {Mon,

              Tue,

              Wed,

              Thu,

              Fri,

              Sat,

              Sun };

 

public class testClass

{

 

public static void foo()

{

  test__0 Day = test__0.Mon;

}

 

 

If the size of an array is specified by an enumerated type, the size is evaluated from the smallest and greatest value of the type.

 

 

type

  TEnum = (cm1, cm2, cm3, cm4, cm5, cm6);

 

var

  foo : Array[TEnum] Of String;

 

->

 

public enum TEnum {cm1,

            cm2,

            cm3,

            cm4,

            cm5,

            cm6 };

public static string[] foo = new string[6/*# TEnum*/];

 



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content