Arrays, Lists, and Collections in C#
Learn C# (C sharp) in FREE step-by-step lessons.
Module 09: Arrays, Lists, and Collections in C#
Learn how to use arrays, list, and collection
Goals:
- Understand Arrays, Lists, and Collections in C#
Objectives:
- Be able to declare and use an array in C#;
- Use a variable as index to array;
- Be able to handle out of bounds exceptions;
- Cycle through values of an array;
- Work with arrays in conjunction with other controls;
- Differentiate between arrays and lists.
Please study the material at each of the links below.
- Variables as index of Arrays: Finds the total of all values in an array using a loop
Introduction to Arrays: An array is like a list. This shows how to declare and change values in an array- Out of bounds: An exception: If we try to access an element beyond the last element there is a run time error.
Use timer to cycle through colors in an array: Global parallel arrays are used for the color names and colors. Make sure the subscript is not out of bounds.- Colors: Add an array of strings to combo box: A global array of color names is created. In form load, a loop, adds the colors to combo box.
- Colors: Change the color to selected color in combo box: Uses parallel arrays: a string with color names and Color objects
Wishes: At timer event lables are given random font, color and text from arrays.
Comparison of arrays and lists: Examples of declaring arrays vs. lists
Advice: An application with a List and Timer: A list of good advice is randomly selected and scrolls across the form.
Season: A special type of search: An array of first day of season is searched to find where the selected date belongs.
Glossary for arrays lessonFull Glossary