c# - How to pass an array as a parameter to a method

Pass array as parameter
pass-array-as-parameter.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
  
<!DOCTYPE html>  
<script runat="server">

    static void changeArrayItems(int[] arr)
    {
        for (int i = 0; i < arr.Length;i++ )
        {
            arr[i] += 1;
        }
    }  
    protected void Button1_Click(object sender, System.EventArgs e)  
    {
        int[] numbers = new int[]
        {
            5,
            10,
            15,
            20
        };

        Label1.Text = "numbers array.........<br />";
        foreach(int i in numbers)
        {
            Label1.Text += i.ToString() + "<br />";
        }

        changeArrayItems(numbers);
        Label1.Text += "<br /><br />after calling custom function. numbers array.........<br />";
        foreach (int i in numbers)
        {
            Label1.Text += i.ToString() + "<br />";
        }
    }  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>c# example - pass array as parameter</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:DarkBlue; font-style:italic;">  
            c# example - pass array as parameter
        </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="pass array as parameter"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>  
    </form>  
</body>  
</html>
More c# examples