System.Globalization.CompareInfo.CompareInfo.Compare C# (CSharp) Method

Compare() public method

public Compare ( string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options ) : int
string1 string
offset1 int
length1 int
string2 string
offset2 int
length2 int
options CompareOptions
return int
		public virtual int Compare (string string1, int offset1,
					    int length1, string string2,
					    int offset2, int length2,
					    CompareOptions options)
		{
			if ((options & ValidCompareOptions) != options)
				throw new ArgumentException ("options");

			if (string1 == null) {
				if (string2 == null)
					return 0;
				return -1;
			}
			if (string2 == null)
				return 1;

			/* Not in the spec, but ms does these short
			 * cuts before checking the offsets (breaking
			 * the offset >= string length specified check
			 * in the process...)
			 */
			if((string1.Length == 0 ||
				offset1 == string1.Length ||
				length1 == 0) &&
				(string2.Length == 0 ||
				offset2 == string2.Length ||
				length2 == 0))
					return(0);

			if(offset1 < 0 || length1 < 0 ||
			   offset2 < 0 || length2 < 0) {
				throw new ArgumentOutOfRangeException ("Offsets and lengths must not be less than zero");
			}
			
			if(offset1 > string1.Length) {
				throw new ArgumentOutOfRangeException ("Offset1 is greater than or equal to the length of string1");
			}
			
			if(offset2 > string2.Length) {
				throw new ArgumentOutOfRangeException ("Offset2 is greater than or equal to the length of string2");
			}
			
			if(length1 > string1.Length-offset1) {
				throw new ArgumentOutOfRangeException ("Length1 is greater than the number of characters from offset1 to the end of string1");
			}
			
			if(length2 > string2.Length-offset2) {
				throw new ArgumentOutOfRangeException ("Length2 is greater than the number of characters from offset2 to the end of string2");
			}
			
			return(internal_compare_switch (string1, offset1, length1,
						 string2, offset2, length2,
						 options));
		}

Same methods

CompareInfo.CompareInfo::Compare ( string string1, int offset1, int length1, string string2, int offset2, int length2 ) : int
CompareInfo.CompareInfo::Compare ( string string1, int offset1, string string2, int offset2 ) : int
CompareInfo.CompareInfo::Compare ( string string1, int offset1, string string2, int offset2, CompareOptions options ) : int
CompareInfo.CompareInfo::Compare ( string string1, string string2 ) : int
CompareInfo.CompareInfo::Compare ( string string1, string string2, CompareOptions options ) : int