Nested types |
Top Previous Next |
New features since Delphi 7 > Generics > Nested types
A nested type within a generic is itself a generic.
type TFoo<T> = class type TBar = class X: Integer; // ... end; end;
// ... TBaz = class type TQux<T> = class X: Integer; // ... end; // ... end;
var n: TFoo<Double>.TBar;
->
private class TFoo<T> : TObject {
public class TBar : TObject { public int X; // ...
public TBar() {} };
public TFoo() {} };
// ...
private class TBaz : TObject {
public class TQux<T> : TObject { public int X; // ...
public TQux() {} }; // ...
public TBaz() {} }; private static TFoo<double>.TBar N = null;
A generic can also be declared within a regular class as a nested type:
type TOuter = class type TData<T> = class FFoo1: TFoo<Integer>; // declared with closed constructed type FFoo2: TFoo<T>; // declared with open constructed type FFooBar1: TFoo<Integer>.TBar; // declared with closed constructed type FFooBar2: TFoo<T>.TBar; // declared with open constructed type FBazQux1: TBaz.TQux<Integer>; // declared with closed constructed type FBazQux2: TBaz.TQux<T>; // declared with open constructed type //... end; var FIntegerData: TData<Integer>; FStringData: TData<String>; end;
->
public class TOuter : TObject { public class TData<T> : TObject { public TFoo<int> FFoo1; // declared with closed constructed type public TFoo<T> FFoo2; // declared with open constructed type public TFoo<int>.TBar FFooBar1; // declared with closed constructed type public TFoo<T>.TBar FFooBar2; // declared with open constructed type public TBaz.TQux<int> FBazQux1; // declared with closed constructed type public TBaz.TQux<T> FBazQux2; // declared with open constructed type //...
public TData() {} }; public TData<int> FIntegerData; public TData<string> FStringData;
public TOuter() {} };
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |