xsharp.eu • Array.Find or Predicate use in X#
Page 1 of 1

Array.Find or Predicate use in X#

Posted: Fri Aug 12, 2016 3:07 am
by wriedmann
The prototype of the static method Array.Find is as follows:

Code: Select all

public static T Find<T>(
	T[] array,
	Predicate<T> match
)
and a C# sample is this:

Code: Select all

string [] arr = {"One","Two","Three"};
var results = Array.FindAll(arr, s => s.Equals("One"));
The X# code is as follows:

Code: Select all

local aString as string[]
aString	:= <string>{ "one", "two", "three", "four" }
var cFind := Array.Find( aString, {|c| c == "two" } )
As you can see, the codeblock syntax works also in this case.

Array.Find or Predicate use in X#

Posted: Mon Aug 15, 2016 2:32 pm
by robert
Wolfgang,

The codeblock syntax works, because actually in X# it is really not just a codeblock syntax, but the syntax for an anonymous method.
You can even use multiple statements in the block if you want.

We are inspecting the context to determine if we need a VO compatible codeblock, a delegate implementation or a predicate like in this case.

Robert