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
Sort A List of Ages of Students (Solution: Stack / O(N^3) Complexity)
https://www.usgatmtu.mtu.edu/profile/watch-the-bad-guys-online-streaming/profile
Fórum SO ➡ Merging 2 lists by Name and adding their Values, using LINQ ♦
Reflection 2
4.2 Casting
compiled prog
project euler 13, C#
Математика
and
Plt-D v.0.9 WOA