Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.46 KB, 2 trang )
Chapter 10 Quick Reference
To Do this
Declare an array
variable
Write the name of the element type, followed by square brackets,
followed by the name of the variable, followed by a semicolon.
For example:
bool[] flags;
Create an instance of
an array
Write the keyword new, followed by the name of the element type,
followed by the size of the array between square brackets. For
example:
bool[] flags = new bool[10];
Initialize the elements
of an array instance
to specific values
Write the specific values in a comma-separated list between curly
brackets. For example:
bool[] flags = { true, false, true, false };
Find the number of
elements in an array
Use the Length property. For example:
int noOfElements = flags.Length;
Access a single array
element
Write the name of the array variable, followed by the integer index
of the element between square brackets. Remember, array
indexing starts at zero, not one. For example: