c# example - array contains case insensitive
array-contains-case-insensitive.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
string[] birds = new string[]
{
"Brown Pelican",
"Great White Pelican",
"Peruvian Booby",
"European Shag",
"Guanay Cormorant"
};
Label1.Text = "birds array.........<br />";
foreach (string s in birds)
{
Label1.Text += s + "<br />";
}
Boolean result = birds.Contains("Guanay Cormorant", StringComparer.CurrentCultureIgnoreCase);
Label1.Text += "<br />'Guanay Cormorant' bird contains in birds array? " + result;
// choose any one way
//Boolean result2 = birds.Contains("gUaNay Cormorant", StringComparer.InvariantCultureIgnoreCase);
//Boolean result2 = birds.Contains("gUaNay Cormorant", StringComparer.CurrentCultureIgnoreCase);
Boolean result2 = birds.Contains("gUaNay Cormorant", StringComparer.OrdinalIgnoreCase);
Label1.Text += "<br /><br />'gUaNay Cormorant' bird contains in birds array? " + result2;
Boolean result3 = birds.Contains("Flightless Cormorant", StringComparer.CurrentCultureIgnoreCase);
Label1.Text += "<br /><br />'Flightless Cormorant' bird contains in birds array? " + result3;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - array contains case insensitive</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
c# example - array contains case insensitive
</h2>
<hr width="550" align="left" color="LightBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="check array contains case insensitive"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
