How to Add Items to an Array in ASP
- 1). Create your array variable. You cannot use variables until they are defined in your code. The following instructions show you how to create an array variable for a group of strings and integers:
string arrayStrings[] = new string[2];
int arrayIntegers[] = new int[2];
In these array variables, each array allows for two values. - 2). Add some value to the string array. Since you define "arrayStrings" as a group of string values, you can only add string values to the array. The following code shows you how to add strings:
arrayStrings[0] = "orange";
arrayStrings[1] = "purple";
Notice the first value is the "0" entry in the array. Arrays start with the "0" index. Therefore, if you allow for two values, your array starts with the "0" index and ends with the "1" index. - 3). Add values to the integer array. Like the string array, only integers can be added to an integer array. The following code shows you how to add integers to an array:
arrayIntegers[0] = 12;
arrayIntegers[1] = 13;