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;

No comments:

Post a Comment