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

TOPIC:

Array.Find or Predicate use in X# 12 Aug 2016 05:07 #301

  • wriedmann
  • wriedmann's Avatar
  • Topic Author


  • Posts: 3245
  • 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

    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# 15 Aug 2016 16:32 #305

    • robert
    • robert's Avatar


  • Posts: 3286
  • 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

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

    • Page:
    • 1