おそらくSortedSetが必要です:http:
//msdn.microsoft.com/en-us/library/dd412070.aspx
.net 4.0を使用していない場合は、PowerCollectionプロジェクトで入手できます:http:
//powercollections.codeplex.com/
.Net4.0SortedSetの例
SortedSet<float> set = new SortedSet<float>( );
set.Add(13.3f);
set.Add(0.5f);
set.Add(5.5f);
Console.WriteLine(string.Format("Minimum Value: {0}", set.Min)); // prints 0.5
Console.WriteLine(string.Format("Maximum Value: {0}", set.Max)); // prints 13.3
foreach (float f in set)
{
Console.WriteLine(f);
}
// prints:
// 0.5
// 5.5
// 13.3
// using custom IComparer<float>, see implementation below
set = new SortedSet<float>(new FloatDescComparere());
set.Add(13.3f);
set.Add(0.5f);
set.Add(5.5f);
Console.WriteLine(string.Format("Minimum Value: {0}", set.Min)); // prints 13.3
Console.WriteLine(string.Format("Maximum Value: {0}", set.Max)); // prints 0.5
foreach (float f in set)
{
Console.WriteLine(f);
}
// prints:
// 13.3
// 5.5
// 0.5
説明IComparer:
private class FloatDescComparere : IComparer<float>
{
public int Compare(float x, float y)
{
if (y > x)
return 1;
else if (x > y)
return -1;
else
return 0;
}
}