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>
- How to sum all elements of an int array
- How to use array any
- How to use linq any operator with a string array
- How to get value of a specified element of an array
- How to insert an element to an array
- How to get maximum and minimum values from an int array
- How to display a range of items from an array
- How to remove the first element from an array
- How to remove the last element from an array
- How to get a subset of an array