Search

Tuesday, March 25, 2014
0 comments

Print element of array at specific position in c#, LINQ subset array

6:54 PMTuesday, March 25, 2014
Using the LINQ subset array you can print element of array at specific position through Skip( ) method. If you want to print array element at position number 3 then you should skip three starting index of array. Like
ArrayName .Skip(3).Take(2).ToArray( ) .

Source

<form id="form1" runat="server">
    <div>  
        <asp:Button ID="Button1" runat="server" Height="33px" onclick="Button1_Click"
            Text="Button" Width="96px" />  
    </div>
    <p style="width: 118px">
        <asp:Label ID="Label1" runat="server" Height="40px" Text="Label" Width="100px"></asp:Label>
    </p>
    </form>

Business Logic Code

 protected void Button1_Click(object sender, EventArgs e)
    {
        string[] Vegetables = new string[]
        {
            "Tomato",
            "Potato",
            "Onion",
            "Carrot",
            "Sweet-Potato",
            "Locky"

        };

        Label1.Text = "Vegetables array...<br />";
        foreach (string Vegetable in Vegetables)
        {
            Label1.Text += Vegetable + "<br />";
        }
        string[] arraySubset = Vegetables.Skip(3).Take(2).ToArray();

        Label1.Text += "<br />Vegetables sub array [element after 3 and count 2]...<br />";
        foreach (string Vegetable in arraySubset)
        {
            Label1.Text += Vegetable + "<br />";
        }

Print element of array at specific position in c#, LINQ subset array
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top