Dictionary TryGetValue case insensitive
dictionary-trygetvalue-case-insensitive.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//initialize a dictionary with keys and values.
Dictionary<string, int> birds = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) {
{"Swan Goose",10},
{"Snow Goose",20},
{"Canada Goose",30},
{"Whooper Swan",40}
};
Label1.Text = "dictionary keys and values..........";
foreach (KeyValuePair<string, int> pair in birds)
{
Label1.Text += "<br />" + pair.Key + " ........ " + pair.Value;
}
int value;
string key = "SNOW Goose";
Label1.Text += "<br /><br />key [" + key + "] value is: ";
if (birds.TryGetValue(key, out value))
{
Label1.Text += value;
}
else
{
Label1.Text += "key [" + key + "] does not exists in dictionary";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - dictionary trygetvalue case insensitive</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - dictionary trygetvalue case insensitive
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="dictionary trygetvalue case insensitive"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to sort a Dictionary in ascending and descending order
- How to sort a Dictionary by DateTime value
- How to use Dictionary TryGetValue
- How to access Dictionary items by index
- How to get index of an item by key from a Dictionary
- How to update a key in a Dictionary
- How to access Dictionary items
- How to iterate through a Dictionary using for loop
- How to find duplicate values from a Dictionary
- How to create a Dictionary from a list