Question: 7. The .NET Framework has another structure that handles many of the issues associated with arrays a little easier. This is the List, which is
7. The .NET Framework has another structure that handles many of the issues associated with arrays a little easier. This is the List, which is commonly referred to as the collection of elements. It is an object, which provides us with the ability to add an item, remove an item (from any location in the List), peek an item, and also move an item from one place in the list to another. These functions are not easily applied to the array, and therefore the List provides more flexibility depending on the date you want to collect. However, if the number of elements in the List is known, or if the List is of a small fixed size, or if the efficiency in using primitive data types is important, it is better to use arrays. In this case, using the List will cause your program to run slower. Similarly to the array, the List collection can be used to hold object references and primitive dato types (e.g., double or integer). Your task is now to create a List to hold an undetermined number of names. Consider setting up a new list of students at the start of the term. You will need all names, but until they arrive you are unsure how many students there will be. Continue with the current project and declare the List. This process is very similar to declaring any other object. We must tell it what object (i.e., give it a class name) we are creating (i.e., List), provide it with a type (e.g., String), and instantiate the instance of the object using the keyword new . Declare the List of type String by typing the following code: List(strings myStudentList . now Listestrip(); In this exercise, we are going to use the Random .NET class to generate a random integer between 1 and 12 to determine the amount of elements we are going to store. To set up the random value for the number of students in the class, add the following code: Random randonValue . new Random (); int randomly randomValue. Next (1, 12), Like for the array, the contents of the List are known as elements. However, unlike for the array, we do not need to know the position or index that an element is being added to. For the List, date is added to the end of it. If we want to add date at a particular position in the List, then we can also achieve this. Therefore, we have two different methods we can use when adding information to the List. - The Add method adds data to the end of the List, e.g. myList.Add ( "objectToAdd"). - The Insert method adds date to the List at a specific index. Therefore, we feed the Insert method with the index as well as the date we want to add; e.g. myList. Insert (2, "objectToAdd"). In this example, we will use the Add method. We will use a for loop to add elements to the List until the counter has reached the value of the previously declared variable randomNumber. Implement this vie the following code: Console.WriteLine("You now need to add " students to your class list"); for (int i = 0; i