
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Case-insensitive Dictionary in C#
To compare, ignoring case, use the case-insensitive Dictionary.
While declaring a Dictionary, set the following property to get case-insensitive Dictionary −
StringComparer.OrdinalIgnoreCase
Add the property like this −
Dictionary <string, int> dict = new Dictionary <string, int> (StringComparer.OrdinalIgnoreCase);
Here is the complete code −
Example
using System; using System.Collections.Generic; public class Program { public static void Main() { Dictionary <string, int> dict = new Dictionary <string, int> (StringComparer.OrdinalIgnoreCase); dict.Add("cricket", 1); dict.Add("football", 2); foreach (var val in dict) { Console.WriteLine(val.ToString()); } // case insensitive dictionary i.e. "cricket" is equal to "CRICKET" Console.WriteLine(dict["cricket"]); Console.WriteLine(dict["CRICKET"]); } }
Output
[cricket, 1] [football, 2] 1 1
- Related Articles
- Case-insensitive string comparison in C++
- Case insensitive search in Mongo?
- MySQL case-insensitive DISTINCT?
- Is Python case-sensitive or case-insensitive?
- How to use case-insensitive switch-case in JavaScript?
- JavaScript Count characters case insensitive
- Perform case insensitive SELECT using MySQL IN()?
- JavaScript Check for case insensitive values?
- MongoDB query with case insensitive search?
- How to perform case-insensitive search in Oracle?
- What is an alternative to string.Replace that is case-insensitive in C#?
- How to achieve case sensitive uniqueness and case insensitive search in MySQL?
- MongoDB query for specific case insensitive search
- Case-insensitive string replacement using Python Program
- How to make a case-insensitive query in MongoDB?

Advertisements