Search

Friday, April 18, 2014
0 comments

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

6:29 AMFriday, April 18, 2014

Introduction

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" />
    <div>  
        <asp:Label ID="Label1" runat="server" BackColor="Yellow"></asp:Label>  
    </div>
    </form>


Code behind code
 protected void Button1_Click(object sender, EventArgs e)
    {
        {
            string[] Fruits = new string[]
        {
            "Apple",
            "Banana",
            "Mango",
            "Orange",  
        };
            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 />";
            }
        }
OutPut-

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top