Write a program in C#.Net to find the sum of all elements in the array.

Answer:

using System;

namespace SumOfArrayElements
{
    class Program
    {
        static void Main(string[] args)
        {
            // Define an array with some elements
            int[] numbers = { 10, 20, 30, 40, 50 };

            // Variable to hold the sum of elements
            int sum = 0;

            // Loop through the array and add each element to the sum
            for (int i = 0; i < numbers.Length; i++)
            {
                sum += numbers[i];
            }

            // Display the sum of all elements in the array
            Console.WriteLine("The sum of all elements in the array is: " + sum);
            Console.ReadLine();
        }
    }
}
Scroll to Top