Indirekter Function-Aufruf über einen Delegaten
Posted: Fri Mar 01, 2019 8:44 am
Peter,
Here is your example modified to not use a delegate.
Nice one, will definitely go into my examples box.pemo18 wrote:Thank you everyone.
This is the shortest (and still readable) version I came up with:
No you don't, but using a delegate can shorten some very complex if statements to a one liner, in any language that understand delegates.If XSharp is as close to C# as I assume I probably don't have to use a delegate.
Here is your example modified to not use a delegate.
Code: Select all
USING System
BEGIN NAMESPACE IndirekterAufruf
FUNCTION Start() AS VOID STRICT
VAR funArr := <STRING>{"Cloudy day ahead", ;
"Sunny the whole day", "Rain, rain and even more rain" }
LOCAL z := Random{}:@@Next(1,funArr:Length + 1) as int // @@Next(0, funArr:Length) if /az set
Console.WriteLine("The weather forecast for today: {0}", funArr[z]())
Me too:I even found a translation class
Code: Select all
DELEGATE Translate(AnyString AS STRING) AS STRING
FUNCTION Start() AS VOID
LOCAL lang AS Translate
lang := English
? lang("Ich liebe dich") // I love you
? lang("Je t'aime") // I love you