Interval data type for C# .NET?

前端 未结 8 1890
一个人的身影
一个人的身影 2021-01-30 23:07

I\'m looking an interval data type for .NET 4.0. For example the interval (a,b], all point x such that a

What i would like to be able to do are create interv

8条回答
  •  感情败类
    2021-01-30 23:25

    To get you started:

    public class Interval where T : struct, IComparable
    {
        public T? Start { get; set; }
        public T? End { get; set; }
    
        public Interval(T? start, T? end)
        {
            Start = start;
            End = end;
        }
    
        public bool InRange(T value)
        {
            return ((!Start.HasValue || value.CompareTo(Start.Value) > 0) &&
                    (!End.HasValue || End.Value.CompareTo(value) > 0));
        }
    }
    

提交回复
热议问题