Dictionary get range
dictionary-get-range.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<int, string> birds = new Dictionary<int, string>() {
{1,"Hyacinth Macaw"},
{2,"Burrowing Parakeet"},
{3,"Vulturine Parrot"},
{4,"Great Blue Turaco"},
{5,"Common Cuckoo"},
{6,"Brush Cuckoo"}
};
Label1.Text = "dictionary keys and values..........";
foreach (KeyValuePair<int , string> pair in birds)
{
Label1.Text += "<br />" + pair.Key + " ........ " + pair.Value;
}
int rangeStart = 2;
int rangeEnd = 4;
Label1.Text += "<br /><br />get dictionary keys and values at index range 2 to 4";
for (int i = rangeStart; i <= rangeEnd; i++)
{
Label1.Text += "<br />key: " + birds.Keys.ElementAt(i);
Label1.Text += " value: " + birds.Values.ElementAt(i);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - dictionary get range</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - dictionary get range
</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 get range"
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 remove first element from Dictionary
- How to remove items from Dictionary in foreach loop
- How to remove range of items from a Dictionary
- How to remove items from a Dictionary by condition
- How to remove an item from Dictionary by value
- How to create a Dictionary from a list
- How to reverse a Dictionary items