/// <summary> /// Determine how the supplied Key Collection compares to "this" Key Collection /// negative = "this" is less than "other" /// zero = "this" is equal to "other" /// positive = "this" is greater than other /// Notionally this function returns something akin to the arithmetical difference operation /// "this" - "other" /// </summary> /// <param name="otherKeyCollection">The other Key Collection with which "this" is to be compared</param> /// <returns>negative if "this" is less than "other", zero if "this" is equal to "other", positive if "this" is greater than "other"</returns> public int CompareTo(KeyCollection otherKeyCollection) { int comparisonIndicator = 0; KeyElementDetailList thisKeyElementDetailList = this.DetermineKeyElementDetail(); KeyElementDetailList otherKeyElementDetailList = otherKeyCollection.DetermineKeyElementDetail(); comparisonIndicator = thisKeyElementDetailList.CompareTo(otherKeyElementDetailList); return(comparisonIndicator); }
/// <summary> /// Determine whether the supplied Key Key Collection is effectively equal to "this" Key Collection /// </summary> /// <param name="otherKeyCollection">The other Key Collection with which "this" is to be compared</param> /// <returns>true if "this" is equal to other, or, false if not</returns> public bool Equals(KeyCollection otherKeyCollection) { bool isEqual = false; if (Count == otherKeyCollection.Count) { // Compare the contents of each List isEqual = true; for (int keyElementIndex = 0; (isEqual) && (keyElementIndex < Count); ++keyElementIndex) { isEqual = this[keyElementIndex].Equals(otherKeyCollection[keyElementIndex], StringComparison.CurrentCultureIgnoreCase); } } // Compare the contents of each List return(isEqual); }
private void btnExecute_Click(object sender, EventArgs e) { int intValue = 0; // Debug.WriteLine("Value is {0} but other value is {1}", 1.ToString(), 2.ToString()); if (Int32.TryParse("17.10", out intValue)) { Console.WriteLine("Success"); } else { Console.WriteLine("Failure"); } lblResult.Text = "Unknown"; if (txtKeyElement0.Text == "") { lblResult.Text = "Key Element 0 is empty"; } else if (txtKeyElement1.Text == "") { lblResult.Text = "Key Element 1 is empty"; } else { // Neither are empty KeyCollection keyCollection0 = new KeyCollection(txtKeyElement0.Text); KeyCollection keyCollection1 = new KeyCollection(txtKeyElement1.Text); int compare0with1Result = keyCollection0.CompareTo(keyCollection1); if (compare0with1Result == 0) { lblResult.Text = "Equal to"; } else if (compare0with1Result < 0) { lblResult.Text = "Less Than"; } else { lblResult.Text = "Greater Than"; } } // Neither are empty }