Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Ranges thing
using System; using System.Collections.Generic; namespace Rextester { public class Program { public static void Main(string[] args) { float test = 25.5f; switch (test) { case float n when n.IsBetween(0, 25): Console.WriteLine("First range inclusive"); break; case float n when n.IsBetween(26, 50): Console.WriteLine("Second range inclusive"); break; case float n when n.IsBetween(51, 75): Console.WriteLine("Third range inclusive"); break; case float n when n > 76: Console.WriteLine("Last range inclusive"); break; default: Console.WriteLine("Default inclusive"); break; } switch (test) { case float n when n.IsBetween(0, 25, false): Console.WriteLine("First range exclusive"); break; case float n when n.IsBetween(25, 50, false): Console.WriteLine("Second range exclusive"); break; case float n when n.IsBetween(50, 75): Console.WriteLine("Third range inclusive"); break; case float n when n > 75: Console.WriteLine("Last range inclusive"); break; default: Console.WriteLine("Default exclusive"); break; } } } public static class Extensions { public static bool IsBetween<T>(this T value, T min, T max, bool inclusive=true) where T : IComparable { return inclusive ? Comparer<T>.Default.Compare(value, min) >= 0 && Comparer<T>.Default.Compare(value, max) <= 0 : Comparer<T>.Default.Compare(value, min) > 0 && Comparer<T>.Default.Compare(value, max) < 0; } } }
run
|
edit
|
history
|
help
0
Delegates
Dotnetq5
circular linked list
Fuuuu
Compare 2 int
NumberSeenSample
asxsadxsdf
two words are anagrams
p link gener tor
Arreglo