Array là base class cho tất cả mảng, namespace System.
Các phương thức chính:
| Sr.No | Phương thức & Mô tả |
|---|---|
| 1 | Clear - Set range phần tử về 0/false/null. |
| 2 | Copy(Array, Array, Int32) - Copy range phần tử. |
| 3 | CopyTo(Array, Int32) - Copy toàn bộ 1D array sang 1D array khác. |
| 4 | GetLength - Số phần tử trong dimension. |
| 5 | GetLongLength - 64-bit version. |
| 6 | GetLowerBound - Lower bound của dimension. |
| 7 | GetType - Type của instance. |
| 8 | GetUpperBound - Upper bound của dimension. |
| 9 | GetValue(Int32) - Giá trị tại vị trí 1D array. |
| 10 | IndexOf(Array, Object) - Tìm index đầu tiên của object. |
| 11 | Reverse(Array) - Đảo ngược thứ tự 1D array. |
Các thuộc tính:
| Sr.No | Thuộc tính & Mô tả |
|---|---|
| 1 | IsFixedSize |
| 2 | IsReadOnly |
| 3 | Length - Tổng số phần tử tất cả dimension. |
| 4 | LongLength - 64-bit Length. |
| 5 | Rank - Số chiều (rank) của mảng. |
Ví dụ Reverse kiểm tra palindrome
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
string string1 = "Level", rev;
char[] ch = string1.ToCharArray();
Array.Reverse(ch);
rev = new string(ch);
bool b = string1.Equals(rev, StringComparison.OrdinalIgnoreCase);
if (b) Console.WriteLine("String " + string1 + " is a Palindrome!");
else Console.WriteLine("String " + string1 + " is not a Palindrome!");
Console.Read();
}
}
}