Chapter 7. Arrays, Files, and Exceptions in C#
C# makes handling arrays and files extremely easy and introduces exceptions to simplify error handling.
Arrays
In C#, all arrays are zero based. If you declare an array as
int[] x = new int[10];
such arrays have 10 elements, numbered from 0 to 9. Thus, arrays are in line with the style used in C, C++, and Java.
const int MAX = 10; float[] xy = new float[MAX]; for (int i = 0; i < MAX; i++ ) { xy[i] = i; }
You should get into the habit of looping through arrays from zero to the array bounds minus one, as we did in the preceding example.
All array variables have a length property so you can find out how large the array is.
float[] z = new float[20]; for (int j = 0; j< z.Length ; j++) { z[j] ...
Get C# Design Patterns: A Tutorial now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.