Saturday, March 10, 2012

ASp.Net LINQ array search


Here I have used LINQ query to search Array. Using LINQ I have checked if length of array element is greater than or equal to 5 then it will display. LINQ query you can use in array in other parpuse also, for example searching from array and array sorting.



Step 1)Copy and paste below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Xml.Linq;

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

        string fname="";
        string[] instructors = { "Aaron", "Fritz", "Keith", "Scott" ,"sourav"};

        IEnumerable<string> query = from n in instructors
                                    where n.Length >= 5
                                    orderby n ascending
                                    select n;

        foreach (string name in query)
        {
            fname = fname +"<br>"+ name;
        } 

        this.Label1.Text = fname;
    }
}

2 comments:

  1. It is really a great work and the way in which u r sharing the knowledge is excellent.
    Thanks for helping me to understand basic concepts. As a beginner in dot net programming your post help me a lot.Thanks for your informative article.Dot Net training in chennai | dot net training and placement | Dot Net training in velachery


    ReplyDelete