Thuộc tính Array.IsReadOnly nhận một giá trị cho biết liệu Mảng có phải là chỉ đọc hay không.
Đầu tiên, đặt giá trị mảng -
Array arr = Array.CreateInstance(typeof(String), 3);
arr.SetValue("Electronics", 0);
arr.SetValue("Clothing", 1); Bây giờ, hãy sử dụng thuộc tính IsReadOnly để tìm xem Mảng có ở chế độ chỉ đọc hay không. Nếu mảng ở chế độ chỉ đọc, thì nó không thể được cập nhật -
arr.IsReadOnly
Sau đây là ví dụ hoàn chỉnh nêu rõ cách sử dụng thuộc tính Array.IsReadOnly -
Ví dụ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lower {
class Program {
static void Main(string[] args) {
Array arr = Array.CreateInstance(typeof(String), 3);
arr.SetValue("Electronics", 0);
arr.SetValue("Clothing", 1);
Console.WriteLine("Lower Bound: {0}",arr.GetLowerBound(0).ToString());
Console.WriteLine("isReadOnly: {0}",arr.IsReadOnly.ToString());
Console.ReadLine();
}
}
} Đầu ra
Lower Bound: 0 isReadOnly: False