Skip to main content

Posts

Showing posts from January, 2016

Collections

Collection Classes From the last two week's labs you may have already identified some issues related to arrays. We learnt that arrays holds identically typed items. However there are instances when you may requires a more flexible data structure that is capable of growing dynamically without throwing an exception (IndexOutOfRangeException) as in the case of an array. .NET framework's System.Collection classes provides a number of builtIn data structures that are dynamic and typesafe. Some of these classes are generic and others are non-Generic. Generic classes are more typesafe and requires a "type parameter" to be specified. Whereas, the non-generic classes are very loosely typed and should be avoided if possible. Non-Generic Classes System.Collections namespace consists of following non generic classes: ArrayList Queue Stack HashTable SortedList BitArray Issues related to non-generic classes:  Slower executions speed: Can be slower

DSDP Arrays Lab

Week 2 Lab Ex 1 In this lab we learn about Sorting an array, using ForEach loop, and Random class: Open Visual Studio 2012 Create a new project  by going to File --> New --> Project Select Visual C# --> Windows Desktop -->  Console Application In the Name field, type "W2Lab1-[Last_name]", where [Last_Name] is replaced with your last name. In the location field, give a directory location and click ok. Add code to declare and initialize an Int array that can hold 7 Integers. Using a For loop assign random numbers from the range 1 to 49 inclusive to the above array. Sort the array Using a ForEach loop display the seven numbers separated by tabs to console Week 2 Lab Ex 2  In this lab we learn about Linear Search and break: Add new console application project to the above solution Create an array which hold 20 random numbers in the range of 1 and 100. Using a For loop search for an integer given by user. Break out of the loop if the integ