當前位置: 首頁>>代碼示例>>C#>>正文


C# Int32.CompareTo方法代碼示例

本文整理匯總了C#中System.Int32.CompareTo方法的典型用法代碼示例。如果您正苦於以下問題:C# Int32.CompareTo方法的具體用法?C# Int32.CompareTo怎麽用?C# Int32.CompareTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Int32的用法示例。


在下文中一共展示了Int32.CompareTo方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Print

        public void Print()
        {
            System.Int32 i = new System.Int32();
            i = 23;
            Console.WriteLine(i.GetHashCode());
            Console.WriteLine(i.GetType());
            Console.WriteLine(i.GetTypeCode());
            Console.WriteLine(i.ToString());
            if (i.CompareTo(20) < 0)
                Console.WriteLine("{0} < 20", i);
            else if (i.CompareTo(20) == 0)
                Console.WriteLine("i equals 20");
            else
                Console.WriteLine("i > 20");
            Console.WriteLine(System.Int32.MinValue);
            Console.WriteLine(System.Int32.MaxValue);
            Console.WriteLine(System.Double.Epsilon);
            Console.WriteLine(System.Double.PositiveInfinity);
            Console.WriteLine(System.Double.NegativeInfinity);
            Console.WriteLine(System.Boolean.FalseString);
            Console.WriteLine(System.Boolean.TrueString);

            Console.WriteLine(System.Char.IsDigit('1'));
            Console.WriteLine(System.Char.IsLetter('9'));
            Console.WriteLine(System.Char.IsWhiteSpace("naynish chaughule", 7));
            Console.WriteLine(System.Char.IsPunctuation('?'));

            //parsing
            double d = System.Double.Parse("90.35");
            Console.WriteLine(d);
            System.Int64 longVar = Convert.ToInt64("43654703826562");
            Console.WriteLine(longVar);

            Console.WriteLine(System.Guid.NewGuid());
            System.DateTime dt = new DateTime(2012, 6, 04);
            Console.WriteLine(dt.ToLongDateString());
            Console.WriteLine(DateTime.Now.ToLongTimeString());
            Console.WriteLine(dt.DayOfWeek);
            Console.WriteLine(dt.AddMonths(5).ToLongDateString());
            Console.WriteLine("{0} {1} {2}", dt.Date, dt.DayOfYear, dt.IsDaylightSavingTime());

            TimeSpan ts = new TimeSpan(24, 30, 30);
            Console.WriteLine(dt.Add(ts).ToLongDateString());
            Console.WriteLine(ts.Subtract(new TimeSpan(2,30, 45)));
            NumericsDemo();
            WorkingWithStrings();
        }
開發者ID:naynishchaughule,項目名稱:CSharp,代碼行數:47,代碼來源:Hierarchy.cs

示例2: Compare

		private static Int32 Compare(Int32 value1, String value2)
		{
			if (String.IsNullOrEmpty(value2))
				return value1.CompareTo(0);

			if (Boolean.TrueString.Equals(value2, StringComparison.OrdinalIgnoreCase))
				return value1 >= MinTrueInt ? 0 : -1;

			if (Boolean.FalseString.Equals(value2, StringComparison.OrdinalIgnoreCase))
				return value1 >= MinTrueInt ? +1 : 0;

			Int32 parsedIntegerValue;
			if (Int32.TryParse(value2, out parsedIntegerValue))
				return value1.CompareTo(parsedIntegerValue);

			Single parsedSingleValue;
			if (Single.TryParse(value2, out parsedSingleValue))
				return ((Single)value1).CompareTo(parsedSingleValue);

			var stringLength = value2.Length;
			return value1.CompareTo(stringLength);
		}
開發者ID:Snarkorboojum,項目名稱:SharpObjects,代碼行數:22,代碼來源:DataObjectValueComparsonTests.cs

示例3: 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 Int32 @this, Int32 minValue, Int32 maxValue)
 {
     return minValue.CompareTo(@this) == -1 && @this.CompareTo(maxValue) == -1;
 }
開發者ID:Nucs,項目名稱:nlib,代碼行數:13,代碼來源:Int32.Between.cs

示例4: AssertComparison

		private static void AssertComparison(Int32 value1, Int32 value2)
		{
			var expectedComparisonResult = value1.CompareTo(value2);
			AssertComparison(new DataObjectValue(value1), new DataObjectValue(value2), expectedComparisonResult);
		}
開發者ID:Snarkorboojum,項目名稱:SharpObjects,代碼行數:5,代碼來源:DataObjectValueComparsonTests.cs


注:本文中的System.Int32.CompareTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。