Sadi02’s Weblog

June 23, 2008

Find data from a data structure(List, Dictionary) using delegate in c# .Net

Filed under: Computer Science — Tags: , , , — Md. Shaik Sadi @ 4:23 am
using System;
using System.Collections.Generic;
using System.Text; 
namespace MyDelegate
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> m_liName=new List<string>();
            m_liName.Add("sadi");
            m_liName.Add("pothik");
            m_liName.Add("shiman");
            m_liName.Add("shuvro");
            m_liName.Add("arif");
 
            //**************Find a single data
            string sName = m_liName.Find(delegate(string s) { return s.Equals("sadi"); });

            //**************Find multiple data
            List<string> liName1 = m_liName.FindAll(delegate(string s) { return s.Equals("sh"); });

            //*************If contains the data**********
            bool bIsSuccess = m_liName.Contains("sadi"); // output: true
        }
    }
}

2 Comments »

  1. how you do this by searching using a textbox or dropdown list presing a button
    then display in a Gridview asp.net

    Comment by Daysy — August 9, 2008 @ 8:00 pm

  2. thanks man for your help its work perfect

    Comment by theKnaya — January 14, 2009 @ 5:30 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.