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

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


ใช้คุณสมบัติ Item ของคลาส ArrayList เพื่อรับหรือตั้งค่าองค์ประกอบที่ดัชนีที่ระบุใน ArrayList

คุณสมบัติ Item เป็นตัวสร้างดัชนี คุณจึงสามารถใช้งานได้โดยไม่ต้องเพิ่มชื่อคุณสมบัติ

ในตัวอย่างด้านล่าง เราได้ใช้มันเหมือนคำสั่งต่อไปนี้ −

Console.WriteLine("Element {0} is \"{1}\"", 2, arrList[1]);

ให้เราดูตัวอย่างที่สมบูรณ์เพื่อเรียนรู้วิธีทำงานกับคุณสมบัติ Item

ตัวอย่าง

using System;
using System.Collections;
class Demo {
   public static void Main() {
      ArrayList arrList = new ArrayList();
      arrList.Add(45);
      arrList.Add(78);
      arrList.Add(88);
      Console.WriteLine("Total elements: "+arrList.Count);
      Console.WriteLine("Element {0} is \"{1}\"", 2, arrList[1]);
   }
}

ผลลัพธ์

Total elements: 3
Element 2 is "78"