Description
The project is asking me to create a code using single dimensional arrays to compute the weekly hours for each employee (there are 8). So I have to gather the hours each employee has worked in one week. Then I have to get the sum of the hours worked
Explanation & Answer
You can declare a single-dimensional array of five integers as shown in the following example:
This array contains the elements from array[0] to array[4]. The new operator is used to create the array and initialize the array elements to their default values. In this example, all the array elements are initialized to zero.
An array that stores string elements can be declared in the same way. For example:
It is possible to initialize an array upon declaration, in which case, the rank specifier is not needed because it is already supplied by the number of elements in the initialization list. For example:
A string array can be initialized in the same way. The following is a declaration of a string array where each array element is initialized by a name of a day:
When you initialize an array upon declaration, you can use the following shortcuts:
int[] array2 = { 1, 3, 5, 7, 9 }; string[] weekDays2 = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
It is possible to declare an array variable without initialization, but you must use the new operator when you assign an array to this variable. For example:
C# 3.0 introduces implicitly typed arrays. For more information, see Implicitly Typed Arrays (C# Programming Guide).
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
The Sun Is Also a Star
by Nicola Yoon
The Point of it All - A Lifetime of Great Loves and Endeavors
by Charles Krauthammer
The Secret Garden
by Frances Hodgson Burnett
Othello
by Wiliam Shakespeare
Girl in Translation
by Jean Kwok
Fear - Trump in the White House
by Bob Woodward
Murder on the Orient Express
by Agatha Christie
The Life-Changing Magic of Tidying Up
by Marie Kondo