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

Compare() public method

public Compare ( String string1, String string2, CompareOptions options ) : int
string1 String
string2 String
options CompareOptions
return int
        public unsafe virtual int Compare(String string1, String string2, CompareOptions options){

            if (options == CompareOptions.OrdinalIgnoreCase) 
            {
                return String.Compare(string1, string2, StringComparison.OrdinalIgnoreCase);
            }
            
            // Verify the options before we do any real comparison.
            if ((options & CompareOptions.Ordinal) != 0) 
            {
                if (options == CompareOptions.Ordinal) 
                {
                    //Our paradigm is that null sorts less than any other string and
                    //that two nulls sort as equal.
                    if (string1 == null) {
                        if (string2 == null) {
                            return (0);     // Equal
                        }
                        return (-1);    // null < non-null
                    }
                    if (string2 == null) {
                        return (1);     // non-null > null
                    }
                
                    return String.nativeCompareOrdinal(string1, string2, false);
                } else 
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_CompareOptionOrdinal"), "options"); 
                }
            }
            if ((options & ValidCompareMaskOffFlags) != 0) 
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); 
            }
            
            //Our paradigm is that null sorts less than any other string and
            //that two nulls sort as equal.
            if (string1 == null) {
                if (string2 == null) {
                    return (0);     // Equal
                }
                return (-1);    // null < non-null
            }
            if (string2 == null) {
                return (1);     // non-null > null
            }

            
            return (Compare(m_pSortingTable, this.m_sortingLCID, string1, string2, options));
        }

Same methods

CompareInfo::Compare ( String string1, String string2 ) : int
CompareInfo::Compare ( String string1, int offset1, String string2, int offset2 ) : int
CompareInfo::Compare ( String string1, int offset1, String string2, int offset2, CompareOptions options ) : int
CompareInfo::Compare ( String string1, int offset1, int length1, String string2, int offset2, int length2 ) : int
CompareInfo::Compare ( String string1, int offset1, int length1, String string2, int offset2, int length2, CompareOptions options ) : int
CompareInfo::Compare ( void pSortingTable, int sortingLCID, String string1, String string2, CompareOptions options ) : int

Usage Example

Esempio n. 1
0
		internal int AddSorted(TreeNodeEx node)
		{
			int pos = 0;
			string text = node.Text;
			if (childCount > 0)
			{
				System.Globalization.CompareInfo compare = System.Windows.Forms.Application.CurrentCulture.CompareInfo;
				// Simple optimization if added in sort order
				if (compare.Compare(children[(childCount - 1)].Text, text) <= 0)
					pos = childCount;
				else
				{
					// Binary Search
					int i = 0;
					int j = childCount;
					while (i < j)
					{
						int mid = (i + j) / 2;
						if (compare.Compare(children[mid].Text, text) <= 0)
							i = mid + 1;
						else
							i = mid;
					}
					pos = i;
				}
			}

			node.SortChildren();
			InsertNodeAt(pos, node);
			if (treeView != null && node == treeView.SelectedNode)
			{
				treeView.SelectedNode = node;
			}
			return pos;
		}
All Usage Examples Of System.Globalization.CompareInfo::Compare