Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
IComparable extensions: Between
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using IComparableExtensions; namespace Rextester { public class Program { public static void Main(string[] args) { if(5.Between(5, 7, CompareMode.Inclusive)) Console.WriteLine("Hello, world!"); } } } namespace IComparableExtensions { [Flags] public enum CompareMode { Exclusive = 0, IncludeLow = 1, IncludeHigh = 2, Inclusive = IncludeLow | IncludeHigh } public static class IComparableExtensions { public static bool Between<T>(this T self, T low, T high, CompareMode mode) where T : IComparable { var compareLow = (mode & CompareMode.IncludeLow) == CompareMode.IncludeLow ? 0 : 1; var compareHigh = (mode & CompareMode.IncludeHigh) == CompareMode.IncludeHigh ? 0 : -1; return self.CompareTo(low) >= compareLow && self.CompareTo(high) <= compareHigh; } } }
run
|
edit
|
history
|
help
0
Making Anagrams-Final
2.2 Basic types: Dictionary
nikk
,
Funzpoint
13
line 1 syntax error
Range List for C#
Dungeon Game
PolyMorphism