|
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace CChess
{
/// <summary>
/// Defines a simple Range type
/// </summary>
/// <typeparam name="T">The type for which the Range is defined</typeparam>
public class Range<T> where T : IComparable
{
public Range()
{
}
public Range(T val1, T val2)
{
_val1 = val1;
_val2 = val2;
}
/// <summary>
/// One value of the range (NOT the minimum)
/// </summary>
private T _val1;
/// <summary>
/// Second value of the range (NOT the maximum)
/// </summary>
private T _val2;
/// <summary>
/// Gets or sets the first value of the range
/// </summary>
public T Val1
{
get { return _val1; }
set { _val1 = value; }
}
/// <summary>
/// Gets or sets the second value of the range
/// </summary>
public T Val2
{
get { return _val2; }
set { _val2 = value; }
}
/// <summary>
/// If val1 is greater than val2, then val must be greater than val2, but less
/// than val2. If val2 is greater than val1, then val must be greater than val1
/// and less than val2.
/// </summary>
/// <returns>True if val is in the range created by val1 and val2, false otherwise.</returns>
public bool FitsInRange(T val)
{
if (_val1.CompareTo(_val2) > 0)
{
if (val.CompareTo(_val2) > 0 && val.CompareTo(_val1) < 0)
{
return true;
}
else
{
return false;
}
}
else
{
if (val.CompareTo(_val1) > 0 && val.CompareTo(_val2) < 0)
{
return true;
}
else
{
return false;
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
My name is Julian, I was born in Argentina, but I've been living in Israel for 6 years already. I'm a high school student in my last year, I study computer science, physics and math.
Other than programming, I really enjoy watching anime and reading manga.