Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

คุณสมบัติ IsReadOnly ของคลาส SortedList ใน C # คืออะไร


ใช้คุณสมบัติ IsReadOnly เพื่อรับค่าที่ระบุว่า SortedList เป็นแบบอ่านอย่างเดียวหรือไม่

คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้คุณสมบัติ IsReadOnly ใน C#

ที่นี่เราได้ตั้งค่า SortedList ก่อน

SortedList s = new SortedList();

เพิ่มองค์ประกอบ

s.Add("S001", "Jack");
s.Add("S002", "Henry");

ตอนนี้ให้ตรวจสอบ IsReadOnly

Console.WriteLine("IsReadOnly = " + s.IsReadOnly);

ต่อไปนี้เป็นรหัสที่สมบูรณ์

ตัวอย่าง

using System;
using System.Collections;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         SortedList s = new SortedList();
         s.Add("S001", "Jack");
         s.Add("S002", "Henry");
         Console.WriteLine("IsReadOnly = " + s.IsReadOnly);
      }
   }
}

ผลลัพธ์

IsReadOnly = False