Nested routines |
Top Previous Next |
What is translated > Routines > Nested routines In Delphi functions can be nested. Fortunately C# local functions are quite similar.
type TNested = class public iClassVar : Integer; function Test(iOuterParam, iTwiceParam : Integer; s : String): Integer; end;
implementation
function TNested.Test(iOuterParam, iTwiceParam : Integer; s : String): Integer; const cSeparate = ':'; var iFunctionVar : Integer;
procedure NestedTest(iInnerParam, iTwiceParam : Integer); begin result := iClassVar + iOuterParam + iFunctionVar + iInnerParam + iTwiceParam; end;
begin iClassVar := 1; iFunctionVar := 2; NestedTest1(3, 4); result := result + iTwiceParam; end;
->
public class TNested : TObject { public int iClassVar; public int test(int iOuterParam, int iTwiceParam, string s) { int result = 0; const char cSeparate = ':'; int iFunctionVar = 0; void NestedTest(int iInnerParam, int iTwiceParam_1) { result = iClassVar + iOuterParam + iFunctionVar + iInnerParam + iTwiceParam_1; }; iClassVar = 1; iFunctionVar = 2; NestedTest1(3, 4); result = result + iTwiceParam; return result; }
public TNested() {} };
There are some restrictions in C# however. In the example the outer and the inner routine both have a parameter called "iTwiceParam". In C# this isn't allowed. the parameter for the inner routine is rename d to "iTwiceParam_1" therefore. The "_1" stands for level one.
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |