Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value : SortedList « Data Structure « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Data Structure » SortedList 
11.33.4.Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value
using System;
using System.Collections;
using System.Globalization;

public class SamplesSortedList
{
    public static void Main()
    {
        SortedList mySL4 = new SortedList(StringComparer.InvariantCultureIgnoreCase, 3);

        Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):");
        mySL4.Add("FIRST""Hello");
        mySL4.Add("SECOND""World");
        mySL4.Add("THIRD""!");
        try
        {
            mySL4.Add("first""Ola!");
        }
        catch (ArgumentException e)
        {
            Console.WriteLine(e);
        }
        PrintKeysAndValues(mySL4);

    }

    public static void PrintKeysAndValues(SortedList myList)
    {
        Console.WriteLine("        -KEY-   -VALUE-");
        for (int i = 0; i < myList.Count; i++)
        {
            Console.WriteLine("{0,-6}: {1}",myList.GetKey(i), myList.GetByIndex(i));
        }
    }
}
11.33.SortedList
11.33.1.Create a SortedList using the default comparer
11.33.2.Create a SortedList using the specified case-insensitive comparer
11.33.3.Create a SortedList using the specified CaseInsensitiveComparer, which is based on the Turkish culture (tr-TR)
11.33.4.Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value
11.33.5.Add value to SortedList and get contents by integer indexes
11.33.6.Add element to SortedList by using the indexer.
11.33.7.Show integer indexes of entries
11.33.8.Get value by key indexer
11.33.9.Use the ContainsValue() method to check if mySortedList contains a value
11.33.10.Use the Remove() method to remove a key from SortedList
11.33.11.Get the key at index 3 using the GetKey() method
11.33.12.Get the index of the element with a key using the IndexOfKey() method
11.33.13.Get the index of the element with a value using the IndexOfValue() method
11.33.14.Get the key list using the GetKeyList() method
11.33.15.Get the value list using the GetValueList() method
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.