Example of Array.Copy ( ) method in ASP.NET


If you want to run array until at specified position, you can simply use copy ( ) method. In this method define some parameters. Like array name, index where you want to start from,ending index etc.
<form id="form1" runat="server">

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click"
        BackColor="#99CCFF" />
        <asp:Label ID="Label1" runat="server" BackColor="Yellow"></asp:Label>  

Code behind code
 protected void Button1_Click(object sender, EventArgs e)
            string[] Fruits = new string[]
            Label1.Text = "Fruits array: <br />";
            foreach (string s in Fruits)
                Label1.Text += s + "<br />";
            int length = 3;          
            int index = 1;
            string[] copiedarray = new string[length];
            Array.Copy(Fruits, index, copiedarray, 0, length);
            Label1.Text += "<br /> New array from Fruits array [index no 1 to 3]:<br />";
            foreach (string s in copiedarray)
                Label1.Text += s + "<br />";


Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites