c# - How to get a range of elements from an array

Array get range
array-get-range.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
  
<!DOCTYPE html>  
<script runat="server">  
    protected void Button1_Click(object sender, System.EventArgs e)  
    {
        string[] birds = new string[]
        {
            "Wood Thrush",
            "Japanese Thrush",
            "Mistle Thrush",
            "Austral Thrush",
            "Green Cochoa"
        };

        Label1.Text = "birds array.........<br />";
        foreach(string s in birds)
        {
            Label1.Text += s + "<br />";
        }

        //new destination (copied) array length
        int length = 3;
        //copy start from index 1. second element from birds array.
        int index = 1;
        
        string[] copiedRange = new string[length];
        Array.Copy(birds, index, copiedRange, 0, length);

        Label1.Text += "<br />new array from birds array [index range 1 to 3].........<br />";
        foreach (string s in copiedRange)
        {
            Label1.Text += s + "<br />";
        }
    }  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>c# example - array get range</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:DarkBlue; font-style:italic;">  
            c# example - array get range
        </h2>  
        <hr width="550" align="left" color="LightBlue" />    
        <asp:Label   
            ID="Label1"   
            runat="server"  
            Font-Size="Large"  
            >  
        </asp:Label>  
        <br />
        <asp:Button   
            ID="Button1"   
            runat="server"   
            Text="array get range"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>  
    </form>  
</body>  
</html>
More c# examples