DateTimeOffset - In
A T extension method to determines whether the object is equal to any of the provided values.
public static void Main() { DateTimeOffset [] values = { new DateTimeOffset(2007, 9, 1, 6, 45, 0, new TimeSpan(-7, 0, 0)), new DateTimeOffset(2007, 11, 1, 6, 45, 0, new TimeSpan(-6, 0, 0)), new DateTimeOffset(2007, 10, 1, 8, 45, 0, new TimeSpan(-5, 0, 0))}; DateTimeOffset date = new DateTimeOffset(2007, 10, 1, 8, 45, 0, new TimeSpan(-5, 0, 0)); // C# Extension Method: DateTimeOffset - In if(date.In(values)) { Console.WriteLine("{0} exists in the list.", date); } else { Console.WriteLine("{0} doesn't exists in the list.", date); } }
View Source
using System; public static partial class Extensions { /// <summary> /// A T extension method to determines whether the object is 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 contains the object, else false.</returns> /// ### /// <typeparam name="T">Generic type parameter.</typeparam> public static bool In(this DateTimeOffset @this, params DateTimeOffset[] values) { return Array.IndexOf(values, @this) != -1; } }