Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Asp.Net Check If Arraylist Contains Specific String Value or Not

Jan 8, 2017
Introduction:

Here I will explain how to check if arraylist contains string value or not in
asp.net using c#, vb.net with example or asp.net check arraylist contains value in c#, vb.net with example or find a string in arraylist in c#, vb.net with example or check if value exists in arraylist using c#, vb.net with example or check existence of string value in arraylist in c#, vb.net with example. By using array list contains property we can easily check whether given string value exists in array list object or not in c#, vb.net.

Description :
  
In previous articles I explained
multiple inheritance in c#, vb.net with example , fragment caching in c#, vb.net with example , connection pooling in c#, vb.net with example , simple windows service example in c#, vb.net , difference between IQueryable and IEnumerable with example and many articles relating to asp.net, c# and vb.net . Now I will explain how to check if given string value exists in arraylist in c#, vb.net with examples.

In c# or vb.net to check if arraylist contains given string value or not we need to write the code like as shown below

C# Code

ArrayList arrlist = new ArrayList {"suresh", "rohini", "praveen", "sateesh" };
bool result = arrlist.Contains(txtname.Text.ToLower());

VB.NET Code


Dim arrlist As New ArrayList() From {
"suresh",
"rohini",
"praveen",
"sateesh"
}
Dim result As Boolean = arrlist.Contains(txtname.Text.ToLower())

If you want complete example to check if arraylist contains given string value or not in asp.net using c#, vb.net we need to write the code like as shown below in your web page.


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> Asp.Net Check if Array List Contains String or Not </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td> Enter Name: </td>
<td><asp:TextBox ID="txtname" runat="server"/></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnCheck" runat="server" Text="Check" OnClick="btnCheck_Click" /> </td>
</tr>
</table>
<asp:Label ID="lblmsg" runat="server"/>
</div>
</form>
</body>
</html>

Now open code behind file and write the code like as shown below

C# Code


using System;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{

}
protected void btnCheck_Click( object sender, EventArgs e)
{
ArrayList arrlist = new ArrayList {"suresh", "rohini", "praveen", "sateesh" };
bool result = arrlist.Contains(txtname.Text.ToLower());
if (result)
{
lblmsg.Text = "List Contains Given Name" ;
}
else
{
lblmsg.Text = "Given Name not Exists in List" ;
}
}
}


VB.NET Code


Imports System.Collections
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub btnCheck_Click(sender As Object, e As EventArgs)
Dim arrlist As New ArrayList() From {
"suresh",
"rohini",
"praveen",
"sateesh"
}
Dim result As Boolean = arrlist.Contains(txtname.Text.ToLower())
If result Then
lblmsg.Text = "List Contains Given Name"
Else
lblmsg.Text = "Given Name not Exists in List"
End If
End Sub
End Class
Demo

Following is the result to check if arraylist contains given string in asp.net using c#, vb.net with example.


Asp.Net Check If Arraylist Contains Specific String Value or Not

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.