Given an array initialized with numbers, how can I add all of its elements without using LINQ or foreach?
My incomplete code is as follows:
namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
method1(sum1);
MessageBox.Show("The Sum Is = " + sum1.ToString(), "Addition",MessageBoxButtons.OK,MessageB…
}
int sum1;
int[] str = new int[4] { 1, 2, 3, 4 }; // i want to add this 4 values and to be printed on a messagebox//
public int method1(int str)
{
sum1 = str;
return sum1;
}
}
}
The output is showing "the sum is = 0", instead of 10.
Thank you.
P.S: I don't want to use LINQ or foreach.