本文整理匯總了C#中System.Single.CompareTo方法的典型用法代碼示例。如果您正苦於以下問題:C# Single.CompareTo方法的具體用法?C# Single.CompareTo怎麽用?C# Single.CompareTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Single
的用法示例。
在下文中一共展示了Single.CompareTo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Compare
private static Int32 Compare(Single value1, String value2)
{
if (String.IsNullOrEmpty(value2))
return value1.CompareTo(0.0f);
if (Boolean.TrueString.Equals(value2, StringComparison.OrdinalIgnoreCase))
return value1 >= MinTrueSingle ? 0 : -1;
if (Boolean.FalseString.Equals(value2, StringComparison.OrdinalIgnoreCase))
return value1 >= MinTrueSingle ? +1 : 0;
Single parsedSingleValue;
if (Single.TryParse(value2, out parsedSingleValue))
return value1.CompareTo(parsedSingleValue);
var stringLength = value2.Length;
return value1.CompareTo(stringLength);
}
示例2: Between
/// <summary>
/// A T extension method that check if the value is between (exclusif) the minValue and maxValue.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <param name="minValue">The minimum value.</param>
/// <param name="maxValue">The maximum value.</param>
/// <returns>true if the value is between the minValue and maxValue, otherwise false.</returns>
/// ###
/// <typeparam name="T">Generic type parameter.</typeparam>
public static bool Between(this Single @this, Single minValue, Single maxValue)
{
return minValue.CompareTo(@this) == -1 && @this.CompareTo(maxValue) == -1;
}
示例3: AssertComparison
private static void AssertComparison(Single value1, Single value2)
{
var expectedComparisonResult = value1.CompareTo(value2);
AssertComparison(new DataObjectValue(value1), new DataObjectValue(value2), expectedComparisonResult);
}