DateTime - NotIn
A T extension method to determines whether the object is not equal to any of the provided values.
public static void Main() { DateTime date = new DateTime(2018, 12, 25); DateTime [] values = {new DateTime(2018, 12, 25), new DateTime(2019, 2, 28), new DateTime(2019, 2, 24), new DateTime(2017, 5, 12)}; DateTime maxDate = new DateTime(2019, 2, 28); // C# Extension Method: DateTime - NotIn if(date.NotIn(values)) { Console.WriteLine("Date is not in the list."); } else { Console.WriteLine("Date is in the list."); } }
View Source
using System; public static partial class Extensions { /// <summary> /// A T extension method to determines whether the object is not equal to any of the provided values. /// </summary> /// <param name="this">The object to be compared.</param> /// <param name="values">The value list to compare with the object.</param> /// <returns>true if the values list doesn't contains the object, else false.</returns> /// ### /// <typeparam name="T">Generic type parameter.</typeparam> public static bool NotIn(this DateTime @this, params DateTime[] values) { return Array.IndexOf(values, @this) == -1; } }