Items - Add / Remove
Adding
Accessing Elements
Another method you may use frequently is the GetValue method.
'Will return the value of the 9th element if there is one.
int myValue = myArray.GetValue(9);
We can access an array element by passing the item index to the array
int myValue = myArray[0];
int myValue = myArray[1];
string[] myArray;
string[] myArray = new string[3];
myArray[0] = 5;
myArray[1] = 10;
myArray.SetValue(15,2);
GetValue Method
Removing
Clear method
You can clear a portion of an array with the Clear method.
System.Array.Clear(ArrayName, Index, Length)
ArrayName - The array you want to clear
Index - The starting index of the range of elements to clear
Length - The number of elements to clear
clsComponent gaComponentArray(10, 20)
System.Array.Clear(gaComponentArray, 0, (10 + 1) * (20 + 1))
Another feature is the Clear method. So, if you clear element 2 for instance and you try referencing its length property afterward, you are going to raise a null reference exception.
Array.Clear(aiArrayIntegers, 0, 1)
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext