Question: C#: using System; class FlexibleArrayMethod { static void Main ( ) { / / Declare three integer arrays of different sizes int [ ] array

C#: using System;
class FlexibleArrayMethod
{
static void Main()
{
// Declare three integer arrays of different sizes
int[] array1={1,2,3,4,5};
int[] array2={6,7,8};
int[] array3={9,10,11,12};
// Pass each array to the DisplayAndSum method
DisplayAndSum(array1);
DisplayAndSum(array2);
DisplayAndSum(array3);
}
// Method to display array elements and their sum
static void DisplayAndSum(int[] array)
{
int sum =0;
Console.Write("Array Elements: ");
foreach (int element in array)
{
Console.Write(element +"");
sum += element;
}
Console.WriteLine("
Sum of Array Elements: "+ sum);
Console.WriteLine(); // For better readability
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!