Show/Hide Toolbars

XSharp

Navigation: X# Examples

Lamda Expressions

Scroll Prev Top Next More

Lamda Expressions are very much like CodeBlocks, but the difference is that it has optional typed parameters and return values.
You can also specify the parameter type in the parameter list as the 3rd example shows
 
DELEGATE Multiply(x AS REAL8) AS REAL8
FUNCTION Start AS VOID
  LOCAL del AS Multiply
  del := {e => e * e}
  ? del(1)
  ? del(2)
  ? del(3)
  ? del(4)
  Console.ReadLine()
LOCAL dfunc AS System.Func<Double,Double>
  dfunc :=   {x =>
           ? "square of", x
          RETURN x^2
        }
  ? dfunc(5)
LOCAL typed AS Multiply
  typed :=   {x AS REAL8 =>
           ? "square of", x
          RETURN x^2
        }
  ? typed(6)
RETURN