In C# and using Microsoft Visual Studio and in Windows From Application. If I co
ID: 3680775 • Letter: I
Question
In C# and using Microsoft Visual Studio and in Windows From Application. If I could get a list of names of the tools that need to be dragged into the design window and then what the final code would look like. Also note that there are some modifications to the original problem at the end "amended as follows".
- Create a program named FlexibleArrayMethod that declares at least three integer
arrays of different sizes. In turn, pass each array to a method that displays all the
integers in each array and their sum.
amended as follows.
The arrays should be of sizes 3, 5, 7 (write your program, including array initialization, in the
way applicable to much larger arrays as well). Populate them with random numbers from 1 to 99
generated automatically. The results for each array
should be displayed on a separate line.
Explanation / Answer
Following is the C# code that you need to put in aspx.cs file of your windows application form.Class name can be changed according to your needs.
Below are the functions that you wanted :
class Program
{
static void printarray(int[] newarray)
{
int i,sum=0;
Console.Write(" You entered: ");
for (i = 0; i < newarray.Length; i++)
{
Console.Write("{0} ", newarray[i]);
sum = sum + newarray[i];
}
Console.Write(" And sum of all value is: ", sum);
Console.ReadLine();
}
public void FlexibleArrayMethod()
{
int[] nums1,nums2,nums3; // declare numbers as an int array of any size
nums1 = new int[3]; // nums1 is a 3-element array
nums2 = new int[5]; // nums2 is a 5-element array
nums3 = new int[7]; // nums2 is a 5-element array
Random r = new Random();
for(int i=0;i<3;i++)
{ nums1[i] = r.Next(100); } // Set the limit for the random numbers now they will be between 0 to 100
printArray(nums1);
for(int i=0;i<5;i++)
{ nums2[i] = r.Next(100); }
printArray(nums2);
for(int i=0;i<7;i++)
{ nums3[i] = r.Next(100); }
printArray(nums3);
}
}