示例#1
0
        public static bool LeastThan(char[] left, char[] right)
        {
            //For all relational operators, the collating sequence is used to interpret a
            //character relational expression. The character expression whose value is lower
            //in the collating sequence is less than the other expression. The character
            //expressions are evaluated one character at a time from left to right. You can
            //also use the intrinsic functions (LGE, LLT, and LLT) to compare character
            //strings in the order specified by the ASCII collating sequence. For all
            //relational operators, if the operands are of unequal length, the shorter is
            //extended on the right with blanks. If both char_expr1 and char_expr2 are of
            //zero length, they are evaluated as equal.

            int maxLength = Math.Max(left.Length, right.Length);

            char[] leftCharArray  = Characters.GetCharArray(left, maxLength);
            char[] rightCharArray = Characters.GetCharArray(right, maxLength);

            bool isLeastThan = false;

            for (int i = 0; i < leftCharArray.Length; i++)
            {
                if (leftCharArray[i] != rightCharArray[i])
                {
                    if (leftCharArray[i] < rightCharArray[i])
                    {
                        isLeastThan = true;
                        break;
                    }
                    else if (leftCharArray[i] > rightCharArray[i])
                    {
                        isLeastThan = false;
                        break;
                    }
                }
            }
            return(isLeastThan);
        }
示例#2
0
        public static bool AreEqual(char[] left, char[] right)
        {
            int maxLength = Math.Max(left.Length, right.Length);

            char[] c1 = Characters.GetCharArray(left, maxLength);
            char[] c2 = Characters.GetCharArray(right, maxLength);

            if (c1.Length != c2.Length)
            {
                return(false);
            }

            bool areEqual = true;

            for (int i = 0; i < c1.Length; i++)
            {
                if (c1[i] != c2[i])
                {
                    areEqual = false;
                    break;
                }
            }
            return(areEqual);
        }