C# -> X# Conversion syntax question... Method x<T>....WHERE...

This forum is meant for questions and discussions about the X# language and tools
Post Reply
Anonymous

C# -> X# Conversion syntax question... Method x<T>....WHERE...

Post by Anonymous »

Hi All,
I've a short syntax question: How can I translate this extension method in X#?

Thank you !
Guy Deprez

public static bool IsBetween<T>(this T value, T min, T max) where T:IComparable<T>
{
return (min.CompareTo(value) <= 0) && (value.CompareTo(max) <= 0);
}
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

C# -> X# Conversion syntax question... Method x<T>....WHERE...

Post by Chris »

Hi Guy, the following should do it:

Code: Select all

STATIC METHOD IsBetween<T>(SELF value AS T, min AS T, max AS T) AS LOGIC WHERE T IS IComparable<T>
RETURN (min:CompareTo(value) <= 0) && (value:CompareTo(max) <= 0)
The syntax is very similar to that of c#, just please not the usage of "IS" instead of "I" for the WHERE clause.

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply