calculate sum of element of array plus another in c# code example
Example: in another method display sum of elements in different arrays in c#
using System;
public class funcexer5
{
public static int Sum(int[] arr1)
{
int tot=0;
for (int i = 0;i < arr1.Length; i++)
tot += arr1[i];
return tot;
}
public static void Main()
{
int[] arr1 = [5, 5, 6, 4];
Console.Write("\n\nFunction : Calculate the sum of the elements in an array :\n");
Console.Write("--------------------------------------------------------------\n");
Console.WriteLine("The sum of the elements of the array is {0}", Sum(arr1));
}
}