fbpx

Array.Find or Predicate use in X#

  • Wolfgang Riedmann
  • Wolfgang Riedmann's Avatar Topic Author
  • Offline
More
2 years 5 months ago - 2 years 5 months ago #1 by Wolfgang Riedmann
Array.Find or Predicate use in X# was created by Wolfgang Riedmann
The prototype of the static method Array.Find is as follows:
public static T Find<T>(
	T[] array,
	Predicate<T> match
)

and a C# sample is this:
string [] arr = {"One","Two","Three"};
var results = Array.FindAll(arr, s => s.Equals("One"));

The X# code is as follows:
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.
Last edit: 2 years 5 months ago by Wolfgang Riedmann.

Please Log in or Create an account to join the conversation.

More
2 years 5 months ago #2 by Robert van der Hulst
Replied by Robert van der Hulst on topic Array.Find or Predicate use in X#
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
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.