Monday, September 15, 2014

Linq Simple Example with Array C#


  protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "";
        int[] a = { 1, 5, 4, 8, 9, 6 };

        Label1.Text = "Original Array";

        for (int i = 0; i < a.Length; i++)
        {
            Label1.Text += "<br>" + a[i].ToString();
        }

        Label1.Text = "<br>Linq";

        var elements =from element in a where element>5 select element;

        foreach (var x in elements)
        {
            Label1.Text += "<br>" + x;
        }

    }
Output
OutPut Image

No comments:

Post a Comment