/// <summary>
/// Return true if an <see cref="IComparable"/> value is <see cref="Between{T}"/> two inclusive values.
/// </summary>
/// <typeparam name="T"> </typeparam>
/// <param name="target"> </param>
/// <param name="startInclusive"> </param>
/// <param name="endInclusive"> </param>
/// <returns> </returns>
/// <example>5.Between(1, 10) == true</example>
/// <example>5.Between(10, 1) == true</example>
/// <example>5.Between(10, 6) == false</example>
/// <example>5.Between(5, 5)) == true</example>
public static Boolean Between<T>( this T target, T startInclusive, T endInclusive ) where T : IComparable {
return startInclusive.CompareTo( endInclusive ) == 1 ? ( target.CompareTo( startInclusive ) <= 0 ) && ( target.CompareTo( endInclusive ) >= 0 ) : ( target.CompareTo( startInclusive ) >= 0 ) && ( target.CompareTo( endInclusive ) <= 0 );
}
No comments:
Post a Comment