fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Array.Find or Predicate use in X#

Array.Find or Predicate use in X# 2 years 7 months ago #1

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Offline
  • Posts: 1423
  • Karma: 6
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.
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

Last edit: by wriedmann.

Array.Find or Predicate use in X# 2 years 7 months ago #2

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.

  • Page:
  • 1