Array.Find or Predicate use in X#

This forum is meant for examples of X# code.

Post Reply
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Array.Find or Predicate use in X#

Post 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.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Array.Find or Predicate use in X#

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply