Check char array contains a char
The following asp.net c# example code demonstrate us how can we determine/check whether a char array contains
a specified character pogrammatically at run time in an asp.net application. .Net framework's char array each
element value represent a Unicode character.
We can determine whether a specified character exists in a char array by using Contains() method. Enumerable.Contains() method allow us to determine whether a sequence contains a specified element by using the default equality comparer. This method exists in System.Linq namespace.
Contains() method need to pass two parameters named 'source' and 'value'. The 'source' parameter represent a sequence (array) in which to locate the 'value'. And the 'value' parameter represent the value to locate in the sequence.
Contains() method return a Boolean value. It return 'true' if the specified element is found; otherwise it return 'false'. We can call the method as this way to determine a character existence within a char array CharArray.Contains('Character').
We can determine whether a specified character exists in a char array by using Contains() method. Enumerable.Contains() method allow us to determine whether a sequence contains a specified element by using the default equality comparer. This method exists in System.Linq namespace.
Contains() method need to pass two parameters named 'source' and 'value'. The 'source' parameter represent a sequence (array) in which to locate the 'value'. And the 'value' parameter represent the value to locate in the sequence.
Contains() method return a Boolean value. It return 'true' if the specified element is found; otherwise it return 'false'. We can call the method as this way to determine a character existence within a char array CharArray.Contains('Character').
check-char-array-contains-a-char.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
char[] chararray = { 'a','b','c','d','e','f','g'};
Label1.Text = "char array output.........<br />";
foreach (char c in chararray)
{
Label1.Text += c + "<br />";
}
Boolean cExists = chararray.Contains('c');
Boolean pExists = chararray.Contains('p');
Label1.Text += "<br />[c] char contains in char array? " + cExists;
Label1.Text += "<br /><br />[p] char contains in char array? " + pExists;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# linq example - check char array contains a char</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
c# linq example - check char array contains a char
</h2>
<hr width="550" align="left" color="LightBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="check char array contains a char"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to check if an int array contains a value
- How to make array contains case insensitive
- How to check string contains a string in string array
- How to create an array with non-default value
- How to delete an element from an array
- How to find all elements from an array that match the conditions
- How to perform foreach loop through an array elements
- How to get a range of elements from an array
- How to get value of a specified element of an array
- How to insert an element to an array