System.Globalization.SortKey.Compare C# (CSharp) 메소드

Compare() 공개 정적인 메소드

public static Compare ( SortKey sortkey1, SortKey sortkey2 ) : int
sortkey1 SortKey
sortkey2 SortKey
리턴 int
		public static int Compare (SortKey sortkey1, SortKey sortkey2)
		{
			if (sortkey1 == null) {
				throw new ArgumentNullException ("sortkey1");
			}
			if (sortkey2 == null) {
				throw new ArgumentNullException ("sortkey2");
			}

			byte[] keydata1 = sortkey1.key;
			byte[] keydata2 = sortkey2.key;

			if (keydata1.Length == 0) {
				if (keydata2.Length == 0) {
					return 0;
				}
				return -1;
			}
			
			int min_len = (keydata1.Length < keydata2.Length) ? keydata1.Length : keydata2.Length;

			for (int i = 0; i < min_len; i++) {
				if (keydata1[i] > keydata2[i]) {
					return 1;
				} else if (keydata1[i] < keydata2[i]) {
					return -1;
				}
			}

			if (keydata1.Length < keydata2.Length) {
				return -1;
			} else if (keydata1.Length > keydata2.Length) {
				return 1;
			} else {
				return 0;
			}
		}

Usage Example

예제 #1
0
        /// <summary>确定指定的对象是否等于当前的 <see cref="T:System.Globalization.SortKey" /> 对象。</summary>
        /// <returns>如果 <paramref name="value" /> 参数等于当前的 <see cref="T:System.Globalization.SortKey" /> 对象,则为 true;否则为 false。</returns>
        /// <param name="value">将与当前 <see cref="T:System.Globalization.SortKey" /> 对象进行比较的对象。 </param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="value" /> is null.</exception>
        public override bool Equals(object value)
        {
            SortKey sortkey2 = value as SortKey;

            if (sortkey2 != null)
            {
                return(SortKey.Compare(this, sortkey2) == 0);
            }
            return(false);
        }
All Usage Examples Of System.Globalization.SortKey::Compare