Using anonymous methods

Top  Previous  Next

New features since Delphi 7 > Anonymous Methods > Using anonymous methods

 

Anonymous methods in Delphi as well as lambda expressions in C# can be returned by functions and passed to functions as parameters. The following example demonstrates the use as a parameter:

 

 

type

  TFuncOfIntToString = Reference to function(X: Integer): String;

 

procedure AnalyzeFunction(Proc: TFuncOfIntToString);

begin

  Proc(3);

end;

->

 

public delegate string TFuncOfIntToString(int x);

 

 

public static string AnalyzeFunction(TFuncOfIntToString proc)

{

  string result = string.Empty;

  result = proc(3);

  return result;

}

 

 

The use as return value is demonstrated in the next example.

 

 

 

 



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content