private void btnRefresh_Click(object sender, EventArgs e) { List <ListViewItem> list = new List <ListViewItem>(); this.lvFiles.Items.Clear(); DirectoryInfo di = new DirectoryInfo(this._directorySource); foreach (FileInfo fi in di.GetFiles("*.bin")) { try { ListViewItem lvi = new ListViewItem(); lvi.Text = Path.GetFileNameWithoutExtension(fi.Name); string cd = "", md = "", rev = ""; BinaryFormatter bf = new BinaryFormatter(); FileStream fs = fi.Open(FileMode.Open); Project proj = bf.Deserialize(fs) as Project; fs.Close(); fs.Dispose(); if (proj != null) { cd = proj.CreationDate.ToShortDateString(); if (proj.ModificationDate != null) { md = proj.ModificationDate.ToShortDateString(); } rev = proj.Revision.ToString(); lvi.SubItems.Add(cd); lvi.SubItems.Add(md); lvi.SubItems.Add(rev); list.Add(lvi); } } catch { } } list.Sort(new Comparison <ListViewItem>(delegate(ListViewItem l1, ListViewItem l2) { int res = 0; try { if (this.columnSorter == 0) { res = String.Compare(l1.Text, l2.Text); } else if (this.columnSorter == 1) { DateTime dt1 = DateTime.Parse(l1.SubItems[1].Text); DateTime dt2 = DateTime.Parse(l2.SubItems[1].Text); res = DateTime.Compare(dt1, dt2); } else if (this.columnSorter == 2) { DateTime dt1 = DateTime.Parse(l1.SubItems[2].Text); DateTime dt2 = DateTime.Parse(l2.SubItems[2].Text); res = DateTime.Compare(dt1, dt2); } else { Int32 i1 = Int32.Parse(l1.SubItems[3].Text); Int32 i2 = Int32.Parse(l2.SubItems[3].Text); res = i1.CompareTo(i2); } } catch { } return(res); })); foreach (ListViewItem item in list) { this.lvFiles.Items.Add(item); } }
public override int CompareTo(JavaScriptObject obj) { JavaScriptInteger number = (JavaScriptInteger)obj; return(value.CompareTo(number.value)); }
public int CompareTo(SearchOrder other) { return(Order.CompareTo(other.Order)); }
/// <summary> /// /// </summary> /// <param name="current"></param> /// <param name="other"></param> /// <returns></returns> public static int CompareTo(Int32 current, Int32 other) { return(current.CompareTo(other)); }
/// <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); }
private static void Compare_Int32(Int32 a, Int32 b) => AssertEquals(a.CompareTo(b), Comparer <Int32> .Default.Compare(a, b));
} // getSequence /// <summary> /// CompareTo /// </summary> /// <param name="oo">other</param> /// <returns></returns> public int CompareTo(Info_Column oo) { Int32 ii = _sequence; return(ii.CompareTo(oo.GetSequence())); } // compareTo
public Int32 CompareTo(TTL other) => _ttl.CompareTo(other._ttl);
/// <summary> /// Handle comparing the two elements /// </summary> /// <param name="obj"></param> /// <returns></returns> public int CompareTo(object obj) { if (obj is MM_Element == false) { return(1); } if (TEID == 0 && Name != null) // if we have no TEID use name { return(Name.CompareTo(((MM_Element)obj).Name)); } else if (obj is MM_Island && this is MM_Island) { return(((MM_Island)this).ID.CompareTo(((MM_Island)obj).ID)); } else { return(TEID.CompareTo(((MM_Element)obj).TEID)); } /* * MM_Element OtherElem = obj as MM_Element; * int FirstLevel = 0; * if (this.ElemType != OtherElem.ElemType) * FirstLevel = this.ElemType.Index.CompareTo(OtherElem.ElemType.Index); * else if (this is MM_ShuntCompensator) * FirstLevel = (this as MM_ShuntCompensator).CompareShuntCompensators(obj as MM_ShuntCompensator); * else if (this is MM_BusbarSection) * FirstLevel = (this as MM_BusbarSection).CompareBusbarSections(obj as MM_BusbarSection); * else if (this is MM_Unit) * FirstLevel = (this as MM_Unit).CompareUnits(obj as MM_Unit); * else if (this is MM_Load) * FirstLevel = (this as MM_Load).CompareLoads(obj as MM_Load); * * if (FirstLevel != 0) * return FirstLevel; * else if (OtherElem.TEID == TEID) * return 0; * else * { * * MM_Substation Sub = (this is MM_Substation ? this as MM_Substation : this.Substation); * MM_Substation OtherSub = (obj is MM_Substation ? ((MM_Substation)obj) : OtherElem.Substation); * if (Sub == null || OtherSub == null) * { * if (OtherElem.Name != null&& this.Name != null) * return this.Name.CompareTo(OtherElem.Name); * else * return 0; * } * String ThisName = Sub.DisplayName(); * String OtherName = OtherSub.DisplayName(); * * if (String.IsNullOrEmpty(ThisName) || String.IsNullOrEmpty(OtherName)) * return this.Name.CompareTo(OtherElem.Name); * else * { * int SubComp = ThisName.CompareTo(OtherName); * if (SubComp != 0) * return SubComp; * else if (this is MM_TransformerWinding && OtherElem is MM_TransformerWinding) * return this.TEID.CompareTo(OtherElem.TEID); * else * return this.Name.CompareTo(OtherElem.Name); * } * }*/ }
public virtual bool runTest() { Console.Error.WriteLine("Co1117CompareTo runTest() started."); String strLoc = "Loc_000oo"; StringBuilder sblMsg = new StringBuilder(99); int iCountErrors = 0; int iCountTestcases = 0; int in4b = -12; Int32 int4a = 55; Object o1; int retValue; try { strLoc = "Loc_120au"; in4b = -12; o1 = 66; in4b = int4a.CompareTo(o1); ++iCountTestcases; if (!(in4b < 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_337uf! in4b==" + in4b); } in4b = -12; o1 = 55; in4b = int4a.CompareTo(o1); ++iCountTestcases; if (!(in4b == -0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_248ak! in4b==" + in4b); } in4b = -12; o1 = -77; in4b = int4a.CompareTo(o1); ++iCountTestcases; if (!(in4b > 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_411wq! in4b==" + in4b); } strLoc = "Loc_201ax"; in4b = -12; in4b = int4a.CompareTo(null); ++iCountTestcases; if (!(in4b > 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_713tw! in4b==" + in4b); } strLoc = "Loc_202bx"; in4b = -12; in4b = int4a.CompareTo((Type)null); ++iCountTestcases; if (!(in4b > 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_714rw! in4b==" + in4b); } strLoc = "Loc_205ex"; in4b = -12; in4b = (-0).CompareTo(null); ++iCountTestcases; if (!(in4b > 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_716mw! in4b==" + in4b); } strLoc = "Loc_301zv"; in4b = -12; o1 = Int32.MinValue + 1; in4b = (Int32.MinValue).CompareTo(o1); ++iCountTestcases; if (!(in4b < 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_958je! in4b==" + in4b); } strLoc = "Loc_303uv"; Console.Error.WriteLine("Info Inf_774dx. (Integer4.MinValue-Integer4.MaxValue)==" + unchecked (Int32.MinValue - Int32.MaxValue)); strLoc = "Loc_302yv"; in4b = -12; o1 = Int32.MaxValue; in4b = (Int32.MinValue).CompareTo(o1); ++iCountTestcases; if (!(in4b < 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_842sc! in4b==" + in4b); } Object[] os = { Int16.MaxValue, Int64.MaxValue, UInt16.MaxValue, UInt32.MaxValue, UInt64.MaxValue, "Hello World" }; foreach (Object oo in os) { in4b = 0; iCountTestcases++; try{ retValue = in4b.CompareTo(oo); iCountErrors++; Console.WriteLine("Err_3487sdg! No excewpiton thrown : {0}", retValue); }catch (ArgumentException) { }catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_3487sdg! Wrong excewpiton thrown : {0}", ex); } } } catch (Exception exc_general) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_343un! (Co1117CompareTo) exc_general==" + exc_general); Console.Error.WriteLine("EXTENDEDINFO: (Err_343un) strLoc==" + strLoc); } if (iCountErrors == 0) { Console.Error.WriteLine("paSs. Integer4\\Co1117CompareTo.cs iCountTestcases==" + iCountTestcases); return(true); } else { Console.Error.WriteLine("FAiL! Integer4\\Co1117CompareTo.cs iCountErrors==" + iCountErrors); return(false); } }
/// <summary> /// Compares this <see cref="PluginFormat" /> to the given <see cref="PluginFormat" /> /// </summary> /// <remarks> /// <see cref="PluginFormat" />s are strictly ordered by their <see cref="PluginFormat.m_intIndex" />. /// </remarks> /// <param name="other">The <see cref="PluginFormat" /> to which to compare this one.</param> /// <returns> /// A value less than 0 if this instance is less than <paramref name="other" />, or /// 0 if this instance is equal to <paramref name="other" />, or /// a value greater than 0 if this instance is greater than <paramref name="other" />. /// </returns> public int CompareTo(PluginFormat other) { return(m_intIndex.CompareTo(other.m_intIndex)); }
public Int32 CompareTo(EventTime other) => time.CompareTo(other.time).notZero() ?? order.CompareTo(other.order);
/// <summary> /// Compares this instance to a specified <see cref="EventVersion"/> and returns an indication of their relative values. /// </summary> /// <param name="value">An <see cref="EventVersion"/> to compare.</param> public Int32 CompareTo(EventVersion value) { return(version == value.version ? item.CompareTo(value.item) : version.CompareTo(value.version)); }
public int Compare(object o1, object o2) { if (!(o1 is ListViewItem)) { return(0); } if (!(o2 is ListViewItem)) { return(0); } int result = -1; bool resolved = false; if (!reset) { try { switch (dataType) { case "Date": // Parse the two objects passed as a parameter as a DateTime. DateTime firstDate = DateTime.Parse(((ListViewItem)o2).SubItems[ByColumn].Text); DateTime secondDate = DateTime.Parse(((ListViewItem)o1).SubItems[ByColumn].Text); // Compare the two dates. result = DateTime.Compare(firstDate, secondDate); break; case "Int32": // Parse the two objects passed as a parameter as a int. Int32 firstNum = Int32.Parse(((ListViewItem)o2).SubItems[ByColumn].Text); Int32 secondNum = Int32.Parse(((ListViewItem)o1).SubItems[ByColumn].Text); // Compare the two dates. result = firstNum.CompareTo(secondNum); break; case "Double": // Parse the two objects passed as a parameter as a int. Double firsDouble = Double.Parse(((ListViewItem)o2).SubItems[ByColumn].Text); Double secondDouble = Double.Parse(((ListViewItem)o1).SubItems[ByColumn].Text); // Compare the two dates. result = firsDouble.CompareTo(secondDouble); break; default: result = String.Compare(((ListViewItem)o2).SubItems[ByColumn].Text, ((ListViewItem)o1).SubItems[ByColumn].Text); break; } } catch { result = String.Compare(((ListViewItem)o2).SubItems[ByColumn].Text, ((ListViewItem)o1).SubItems[ByColumn].Text); dataType = "string"; } } else { try { // Parse the two objects passed as a parameter as a DateTime. DateTime firstDate = DateTime.Parse(((ListViewItem)o2).SubItems[ByColumn].Text); DateTime secondDate = DateTime.Parse(((ListViewItem)o1).SubItems[ByColumn].Text); // Compare the two dates. result = DateTime.Compare(firstDate, secondDate); resolved = true; dataType = "Date"; } // If neither compared object has a valid date format, compare // as a string. catch { ; } if (!resolved) { try { // Parse the two objects passed as a parameter as a int. Int32 firstNum = Int32.Parse(((ListViewItem)o2).SubItems[ByColumn].Text); Int32 secondNum = Int32.Parse(((ListViewItem)o1).SubItems[ByColumn].Text); // Compare the two dates. result = firstNum.CompareTo(secondNum); resolved = true; dataType = "Int32"; } catch { ; } } if (!resolved) { try { // Parse the two objects passed as a parameter as a int. Double firstNum = Double.Parse(((ListViewItem)o2).SubItems[ByColumn].Text); Double secondNum = Double.Parse(((ListViewItem)o1).SubItems[ByColumn].Text); // Compare the two dates. result = firstNum.CompareTo(secondNum); resolved = true; dataType = "Double"; } catch { result = String.Compare(((ListViewItem)o2).SubItems[ByColumn].Text, ((ListViewItem)o1).SubItems[ByColumn].Text); dataType = "string"; } } } //if (lvi1.ListView.Sorting == SortOrder.Ascending) // result = String.Compare(str1, str2); //else // result = String.Compare(str2, str1); //Determine whether the sort order is descending. if (((ListViewItem)o2).ListView.Sorting == SortOrder.Descending) { // Invert the value returned by String.Compare. result *= -1; } LastSort = ByColumn; reset = false; return(result); }
static void Main(string[] args) { Console.WriteLine("**********************************************************"); Console.WriteLine("****Tipi di dati Integrali e peso in bits o bytes********"); Console.WriteLine("**********************************************************"); sbyte mySbyte = -126; byte myByte = 255; char myChar = 'X'; //short short myIntShort = 32750; short myIntShortNeg = -32750; short myIntShortIdem = 32750; //ushort myIntUnShor = 64999; //int 32 default, 64 long // Int32 myInt = 22456890; Int32 myIntNeg = -22456890; Int32 myIntIdem = 22456890; // Int64 myInt64 = 100222456890; Int64 myInt64Neg = -100222456890; Int64 myInt64Idem = 100222456890; //virgola mobile //float Da ±1.5e−45 e ±3.4e38 7 cifre //double Da ±5.0e−324 a ±1.7e308 15 - 16 cifre float myFloat = 4.55674F; //anche senza segno double myDouble = -1.734567E+3; //con segno e senza //DECIMAL 128 BIT decimal myMoney1 = 300.566666666m; decimal myMoney2 = 3009078904567.556712345678m; Console.WriteLine(""); Console.WriteLine($"tipo sbyte Intero con segno pesa 8 bit, da 128 a -127: value ({mySbyte})"); Console.WriteLine($"tipo Byte Intero senza segno pesa 8 bit, 0 - 255: value ({myByte})"); Console.WriteLine($"tipo Char ' ' carattere Unicode, 16 bit: value({myChar}) e CompareTo ({myChar.CompareTo((Object)'x')}) se negativo/positivo no uguali"); //non uguali menori di zero Console.WriteLine($"tipo Char ' ' carattere Unicode, 16 bit: value({myChar}) e CompareTo ({myChar.CompareTo((Object)'X')}) se zero Uguali"); //Uguali è zero Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine($"tipo Int Short con SEGNO, 16 bit: value({myIntShort}) (risultato : {myIntShort.CompareTo((Object)myIntShortNeg)}) diversi"); //maggiore o minore diversi Console.WriteLine($"tipo Int Short con SEGNO, 16 bit: value({myIntShort}) (risultato : {myIntShort.CompareTo((Object)myIntShortIdem)}) uguali"); //zero allora uguali Console.WriteLine($" value {myIntShort} GetType {myIntShort.GetType()}"); Console.WriteLine("****************************************************************************************"); Console.WriteLine("****int 32bits default con segno********"); Console.WriteLine("****************************************************************************************"); Console.WriteLine(""); Console.WriteLine(""); // int32 default Console.WriteLine($"tipo Int 32 con SEGNO, 32 bit: value({myInt}) (risultato : {myInt.CompareTo((Object)myIntNeg)}) diversi"); //maggiore o minore diversi Console.WriteLine($"tipo Int 32 con SEGNO, 32 bit: value({myInt}) (risultato : {myInt.CompareTo((Object)myIntIdem)}) uguali"); //zero allora uguali Console.WriteLine("****************************************************************************************"); Console.WriteLine("****int 64bits default con segno********"); Console.WriteLine("****************************************************************************************"); Console.WriteLine(""); Console.WriteLine(""); //int64 Console.WriteLine($"tipo Int 64 con SEGNO, 64 bit: value({myInt64}) (risultato : {myInt64.CompareTo((Object)myInt64Neg)}) diversi"); //maggiore o minore diversi Console.WriteLine($"tipo Int 64 con SEGNO, 64 bit: value({myInt64}) (risultato : {myInt64.CompareTo((Object)myInt64Idem)}) uguali"); //zero allora uguali Console.WriteLine("****************************************************************************************"); Console.WriteLine("****Tipi di dati VIRGOLA MOBILE float e double bassa e alta precisione con segno********"); Console.WriteLine("****************************************************************************************"); Console.WriteLine(""); Console.WriteLine(""); //virgola mobile Console.WriteLine($"tipo float virgola mobile bassa precissione (7 cifre)- myFloat = 4.55674F- con SEGNO value: ({myFloat})"); Console.WriteLine($"tipo double virgola mobile alta precissione (15/16 cifre) - double myDouble = -1.734567E+3 - con SEGNO value: ({myDouble})"); //decimal dati a 128 bit. Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("****************************************************************************************"); Console.WriteLine("****Tipi dati DECIMAL dati a 128 bit alta precisione con segno (28/29 cifre)************"); Console.WriteLine("****************************************************************************************"); Console.WriteLine($"tipo decimal 128 BIT ALTA PRECISSIONE precissione (28/ 29 cifre) con SEGNO value: ({myMoney1})"); Console.WriteLine($"tipo decimal 128 BIT ALTA PRECISSIONE (28/ 29 cifre) con SEGNO value: ({myMoney2})"); Console.WriteLine(""); Console.WriteLine(""); //conversioni di tipo //implicite ed esplicite (cast) //Poiché non esiste alcuna conversione implicita tra altri tipi a virgola mobile //e il tipo decimal, è necessario usare un cast per eseguire una conversione tra questi due tipi. Ad esempio: decimal myMoney = 99.9345m; double x = (double)myMoney; // decimal to double // Console.WriteLine("****************************************************************************************"); Console.WriteLine("****decimal to double .... double to decimal ************"); Console.WriteLine("****************************************************************************************"); Console.WriteLine($"decimal to double value: decimal ({myMoney}) (double)myMoney value { x} Risult Covertion GetType >>> ({ x.GetType()})"); Console.WriteLine($"double to decimal value: double ({myMoney}) (decimal)x value { myMoney} Risult Covertion GetType >>> ({ myMoney.GetType()})"); Console.WriteLine(""); myMoney = (decimal)x; // double to decimal //Console.Write(caption); //if (resultGeneric == resultNonGeneric) //{ // if (resultGeneric < 0) relation = "less than"; // else if (resultGeneric > 0) relation = "greater than"; // else relation = "equal to"; // Console.WriteLine("{0} is {1} {2}", var1, relation, var2); //} Console.ReadLine(); ////i1.CompareTo((Object)i2) }
/// <summary> /// A T extension method that check if the value is between inclusively 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 inclusively the minValue and maxValue, otherwise false.</returns> /// ### /// <typeparam name="T">Generic type parameter.</typeparam> public static bool InRange(this Int32 @this, Int32 minValue, Int32 maxValue) { return(@this.CompareTo(minValue) >= 0 && @this.CompareTo(maxValue) <= 0); }
/// <summary>Compares this instance with a specified health and indicates /// whether this instance precedes, follows, or appears in the same position /// in the sort order as the specified health. /// </summary> /// <param name="other"> /// The health to compare with this instance. /// </param> /// <returns> /// A 32-bit signed integer that indicates whether this instance precedes, follows, /// or appears in the same position in the sort order as the value parameter. /// </returns> public int CompareTo(Health other) { return(m_Value.CompareTo(other.m_Value)); }
/// <summary> /// Splits the range in nearly equal sized ranges. /// </summary> /// <param name="includeOddToUpperRange">If the range range is odd where to add the element on the split to?</param> /// <param name="whatToDoWithResults">What to do with the result?</param> /// <returns>Result <see cref="IRangeMathable{UInt16, BigInteger}"/>s.</returns> public IRangeMathableSingleSize <UInt16, BigInteger>[] Split(bool includeOddToUpperRange, RangeMathematicResultUseage whatToDoWithResults) { IRangeMathableSingleSize <UInt16, BigInteger>[] result = new IRangeMathableSingleSize <UInt16, BigInteger> [2]; Int32 tempSize = BigInteger.ToInt32(RangeSize()); switch (tempSize.CompareTo(1)) { case -1: result[0] = default(UInt16RangeMathable); result[1] = default(UInt16RangeMathable); break; case 0: if (includeOddToUpperRange) { result[0] = default(UInt16RangeMathable); result[1] = new UInt16RangeMathable(true, TheRange.StartBound, TheRange.EndBound); } else { result[0] = new UInt16RangeMathable(true, TheRange.StartBound, TheRange.EndBound); result[1] = default(UInt16RangeMathable); } break; case 1: bool storedOddBit = (tempSize & 1) == 1; Int32 halfSize = tempSize >> 1; if (storedOddBit) { if (halfSize > 0) { if (includeOddToUpperRange) { result[0] = new UInt16RangeMathable(false, TheRange.StartBound, (UInt16)(TheRange.StartBound + halfSize - 1)); result[1] = new UInt16RangeMathable(false, (UInt16)(TheRange.EndBound - halfSize), TheRange.EndBound); } else { result[0] = new UInt16RangeMathable(false, TheRange.StartBound, (UInt16)(TheRange.StartBound + halfSize)); result[1] = new UInt16RangeMathable(false, (UInt16)(TheRange.EndBound - halfSize + 1), TheRange.EndBound); } } else { if (includeOddToUpperRange) { result[0] = default(UInt16RangeMathable); result[1] = new UInt16RangeMathable(false, TheRange.EndBound, TheRange.EndBound); } else { result[0] = new UInt16RangeMathable(false, TheRange.StartBound, TheRange.StartBound); result[1] = default(UInt16RangeMathable); } } } else { if (halfSize > 0) { result[0] = new UInt16RangeMathable(false, TheRange.StartBound, (UInt16)(TheRange.StartBound + halfSize - 1)); result[1] = new UInt16RangeMathable(false, (UInt16)(TheRange.EndBound - halfSize + 1), TheRange.EndBound); } else { result[0] = default(UInt16RangeMathable); result[1] = default(UInt16RangeMathable); } } break; } // working with the result to do the wanted actions if ((whatToDoWithResults & RangeMathematicResultUseage.UseLowestResultRangeOnOwnRange) > 0) { if (result[0].StartBound > TheRange.EndBound) { TheRange.EndBound = result[0].EndBound; TheRange.StartBound = result[0].StartBound; } else { TheRange.StartBound = result[0].StartBound; TheRange.EndBound = result[0].EndBound; } TheRange.EmptyRange = result[0].EmptyRange; } else if ((whatToDoWithResults & RangeMathematicResultUseage.UseHighestResultRangeOnOwnRange) > 0) { if (result[1].StartBound > TheRange.EndBound) { TheRange.EndBound = result[1].EndBound; TheRange.StartBound = result[1].StartBound; } else { TheRange.StartBound = result[1].StartBound; TheRange.EndBound = result[1].EndBound; } TheRange.EmptyRange = result[1].EmptyRange; } return(result); }
public virtual bool runTest() { Console.Error.WriteLine("Co1117CompareTo runTest() started."); String strLoc = "Loc_000oo"; StringBuilder sblMsg = new StringBuilder(99); int iCountErrors = 0; int iCountTestcases = 0; int in4b = -12; Int32 int4a = 55; try { LABEL_860_GENERAL: do { strLoc = "Loc_120au"; in4b = -12; in4b = int4a.CompareTo((Int32)66); ++iCountTestcases; if (!(in4b < 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_337uf! in4b==" + in4b); } in4b = -12; in4b = int4a.CompareTo(55); ++iCountTestcases; if (!(in4b == -0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_248ak! in4b==" + in4b); } in4b = -12; in4b = int4a.CompareTo(-77); ++iCountTestcases; if (!(in4b > 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_411wq! in4b==" + in4b); } strLoc = "Loc_201ax"; in4b = -12; in4b = int4a.CompareTo(null); ++iCountTestcases; if (!(in4b > 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_713tw! in4b==" + in4b); } strLoc = "Loc_202bx"; in4b = -12; in4b = int4a.CompareTo((Type)null); ++iCountTestcases; if (!(in4b > 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_714rw! in4b==" + in4b); } strLoc = "Loc_205ex"; in4b = -12; in4b = (-0).CompareTo(null); ++iCountTestcases; if (!(in4b > 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_716mw! in4b==" + in4b); } strLoc = "Loc_301zv"; in4b = -12; in4b = (Int32.MinValue).CompareTo((Int32.MinValue + 1)); ++iCountTestcases; if (!(in4b < 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_958je! in4b==" + in4b); } strLoc = "Loc_303uv"; Console.Error.WriteLine("Info Inf_774dx. (Integer4.MinValue-Integer4.MaxValue)==" + unchecked (Int32.MinValue - Int32.MaxValue)); strLoc = "Loc_302yv"; in4b = -12; in4b = (Int32.MinValue).CompareTo(Int32.MaxValue); ++iCountTestcases; if (!(in4b < 0)) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_842sc! in4b==" + in4b); } strLoc = "Loc_400hh"; try { in4b = -12; in4b = int4a.CompareTo((Int16)22); ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_522yh! in4b==" + in4b); } catch (ArgumentException argexc) {} catch (Exception excep1) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_636pi! excep1==" + excep1); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.Error.WriteLine("POINTTOBREAK: Error Err_343un! (Co1117CompareTo) exc_general==" + exc_general); Console.Error.WriteLine("EXTENDEDINFO: (Err_343un) strLoc==" + strLoc); } if (iCountErrors == 0) { Console.Error.WriteLine("paSs. Integer4\\Co1117CompareTo.cs iCountTestcases==" + iCountTestcases); return(true); } else { Console.Error.WriteLine("FAiL! Integer4\\Co1117CompareTo.cs iCountErrors==" + iCountErrors); return(false); } }
//实现IComparable<Int32>的接口方法 public Int32 CompareTo(Int32 other) { return(_intValue.CompareTo(other)); }
public static int compareTo(object o1, object o2) { try { if (o1 == null || o2 == null) { return(0); } if (!Types.Equals(o1, o1)) { return(0); } if (o1 is bool) { bool v1 = (bool)o1; bool v2 = (bool)o2; return(v1.CompareTo(v2)); } else if (o1 is Boolean) { Boolean v1 = (Boolean)o1; bool v2 = (Boolean)o2; return(v1.CompareTo(v2)); } else if (o1 is byte) { byte v1 = (byte)o1; byte v2 = (byte)o2; return(v1.CompareTo(v2)); } else if (o1 is Byte) { Byte v1 = (Byte)o1; Byte v2 = (Byte)o2; return(v1.CompareTo(v2)); } else if (o1 is short) { short v1 = (short)o1; short v2 = (short)o2; return(v1.CompareTo(v2)); } else if (o1 is Int16) { Int16 v1 = (Int16)o1; Int16 v2 = (Int16)o2; return(v1.CompareTo(v2)); } else if (o1 is UInt16) { UInt16 v1 = (UInt16)o1; UInt16 v2 = (UInt16)o2; return(v1.CompareTo(v2)); } else if (o1 is int) { int v1 = (int)o1; int v2 = (int)o2; return(v1.CompareTo(v2)); } else if (o1 is Int32) { Int32 v1 = (Int32)o1; Int32 v2 = (Int32)o2; return(v1.CompareTo(v2)); } else if (o1 is UInt32) { UInt32 v1 = (UInt32)o1; UInt32 v2 = (UInt32)o2; return(v1.CompareTo(v2)); } else if (o1 is long) { long v1 = (long)o1; long v2 = (long)o2; return(v1.CompareTo(v2)); } else if (o1 is Int64) { Int64 v1 = (Int64)o1; Int64 v2 = (Int64)o2; return(v1.CompareTo(v2)); } else if (o1 is UInt64) { UInt64 v1 = (UInt64)o1; UInt64 v2 = (UInt64)o2; return(v1.CompareTo(v2)); } else if (o1 is float) { float v1 = (float)o1; float v2 = (float)o2; return(v1.CompareTo(v2)); } else if (o1 is double) { double v1 = (double)o1; double v2 = (double)o2; return(v1.CompareTo(v2)); } else if (o1 is string) { string v1 = (string)o1; string v2 = (string)o2; return(v1.CompareTo(v2)); } else if (o1 is String) { String v1 = (String)o1; String v2 = (String)o2; return(v1.CompareTo(v2)); } else if (o1 is DateTime) { DateTime v1 = (DateTime)o1; DateTime v2 = (DateTime)o2; return(v1.CompareTo(v2)); } } catch (Exception) { } return(0); }
public static void Main() { string nl = Environment.NewLine; string msg = "{0}The following is the result of using the generic and non-generic{0}" + "versions of the CompareTo method for several base types:{0}"; DateTime now = DateTime.Now; // Time span = 11 days, 22 hours, 33 minutes, 44 seconds TimeSpan tsX = new TimeSpan(11, 22, 33, 44); // Version = 1.2.333.4 Version versX = new Version("1.2.333.4"); // Guid = CA761232-ED42-11CE-BACD-00AA0057B223 Guid guidX = new Guid("{CA761232-ED42-11CE-BACD-00AA0057B223}"); Boolean a1 = true, a2 = true; Byte b1 = 1, b2 = 1; Int16 c1 = -2, c2 = 2; Int32 d1 = 3, d2 = 3; Int64 e1 = 4, e2 = -4; Decimal f1 = -5.5m, f2 = 5.5m; Single g1 = 6.6f, g2 = 6.6f; Double h1 = 7.7d, h2 = -7.7d; Char i1 = 'A', i2 = 'A'; String j1 = "abc", j2 = "abc"; DateTime k1 = now, k2 = now; TimeSpan l1 = tsX, l2 = tsX; Version m1 = versX, m2 = new Version("2.0"); Guid n1 = guidX, n2 = guidX; // The following types are not CLS-compliant. SByte w1 = 8, w2 = 8; UInt16 x1 = 9, x2 = 9; UInt32 y1 = 10, y2 = 10; UInt64 z1 = 11, z2 = 11; // Console.WriteLine(msg, nl); try { // The second and third Show method call parameters are automatically boxed because // the second and third Show method declaration arguments expect type Object. Show("Boolean: ", a1, a2, a1.CompareTo(a2), a1.CompareTo((Object)a2)); Show("Byte: ", b1, b2, b1.CompareTo(b2), b1.CompareTo((Object)b2)); Show("Int16: ", c1, c2, c1.CompareTo(c2), c1.CompareTo((Object)c2)); Show("Int32: ", d1, d2, d1.CompareTo(d2), d1.CompareTo((Object)d2)); Show("Int64: ", e1, e2, e1.CompareTo(e2), e1.CompareTo((Object)e2)); Show("Decimal: ", f1, f2, f1.CompareTo(f2), f1.CompareTo((Object)f2)); Show("Single: ", g1, g2, g1.CompareTo(g2), g1.CompareTo((Object)g2)); Show("Double: ", h1, h2, h1.CompareTo(h2), h1.CompareTo((Object)h2)); Show("Char: ", i1, i2, i1.CompareTo(i2), i1.CompareTo((Object)i2)); Show("String: ", j1, j2, j1.CompareTo(j2), j1.CompareTo((Object)j2)); Show("DateTime: ", k1, k2, k1.CompareTo(k2), k1.CompareTo((Object)k2)); Show("TimeSpan: ", l1, l2, l1.CompareTo(l2), l1.CompareTo((Object)l2)); Show("Version: ", m1, m2, m1.CompareTo(m2), m1.CompareTo((Object)m2)); Show("Guid: ", n1, n2, n1.CompareTo(n2), n1.CompareTo((Object)n2)); // Console.WriteLine("{0}The following types are not CLS-compliant:", nl); Show("SByte: ", w1, w2, w1.CompareTo(w2), w1.CompareTo((Object)w2)); Show("UInt16: ", x1, x2, x1.CompareTo(x2), x1.CompareTo((Object)x2)); Show("UInt32: ", y1, y2, y1.CompareTo(y2), y1.CompareTo((Object)y2)); Show("UInt64: ", z1, z2, z1.CompareTo(z2), z1.CompareTo((Object)z2)); } catch (Exception e) { Console.WriteLine(e); } }
public Int32 CompareTo(Object obj) { return(value.CompareTo(obj)); }
public static Int32 of(Int32 left, Int32 right) { return(left.CompareTo(right) < 0 ? right : left); }
/// <summary>Compares this instance with a specified house number and indicates /// whether this instance precedes, follows, or appears in the same position /// in the sort order as the specified house number. /// </summary> /// <param name="other"> /// The house number to compare with this instance. /// </param> /// <returns> /// A 32-bit signed integer that indicates whether this instance precedes, follows, /// or appears in the same position in the sort order as the value parameter. /// </returns> public int CompareTo(HouseNumber other) { return(m_Value.CompareTo(other.m_Value)); }
public int CompareTo(Int32CheckedNoThrow other) { return(Value.CompareTo(other.Value)); }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Сравнение объектов для упорядочивания /// </summary> /// <param name="other">Сравниваемый объект</param> /// <returns>Статус сравнения объектов</returns> //--------------------------------------------------------------------------------------------------------- public Int32 CompareTo(TValueInt other) { return(mCurrent.CompareTo(other.mCurrent)); }