Last active
May 22, 2021 13:17
-
-
Save Lahirutech/8c4d0b72ab19745ffa05d3386fd71525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myarray = new ArrayList() | |
{ | |
1, | |
"Bill", | |
300, | |
4.5f | |
}; | |
//Access individual item using indexer | |
int firstElement = (int) myarray[0]; //returns 1 | |
string secondElement = (string) myarray[1]; //returns "Bill" | |
//int secondElement = (int) myarray[1]; //Error: cannot cover string to int | |
//using var keyword without explicit casting | |
var firstElement = myarray[0]; //returns 1 | |
var secondElement = myarray[1]; //returns "Bill" | |
//var fifthElement = myarray[5]; //Error: Index out of range | |
//update elements | |
myarray[0] = "Steve"; | |
myarray[1] = 100; | |
//myarray[5] = 500; //Error: Index out of range |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment