Arrays in C#

If you declare 3 variables as num1, num2, and num3, 3 separate locations in memory are allocated. These are called scalar variables.

scalar

Instead you could declare num to be an array with a size of 3:

int[] num= { 3, 5, 7 };
this.Text = "" + num[1];

The elements of an array are indexed, starting with 0.
You would refer to these values as num[0], num[1], and num[2].

In the example above num[1] is 5, and that is what appears in the text of the form.

Please study the material at each of the links below.

  1. Microsoft Reference: Arrays
  2. Variables as index of Arrays
  3. Out of bounds: An exception
  4. Use timer to cycle through colors in an array
  5. Colors: Add an array of strings to combo box
  6. Colors: Change the color to selected color in combo box
  7. Microsoft Reference: Collections
  8. Comparison of arrays and lists
  9. Microsoft Reference: Arrays
  10. Variables as index of Arrays
  11. Out of bounds: An exception
  12. Use timer to cycle through colors in an array
  13. Colors: Add an array of strings to combo box
  14. Colors: Change the color to selected color in combo box
  15. Microsoft Reference: Collections
  16. Comparison of arrays and lists
  17. Advice: An application with a List and Timer
Like us on Facebook:


OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher: Zebra0.com
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: December 25 2017 16:20:32.