आइए एक लिस्ट संग्रह का उदाहरण देखें।
हमने तत्व सेट किए हैं:
List<int> list = new List<int>(); list.Add(20); list.Add(40); list.Add(60); list.Add(80);
अब मान लें कि हमें लिस्ट से पहला तत्व पुनर्प्राप्त करना है। उसके लिए, इंडेक्स इस तरह सेट करें:
int a = list[0];
निम्नलिखित एक उदाहरण दिखा रहा है कि लिस्ट संग्रह से तत्व कैसे पुनर्प्राप्त करें:
उदाहरण
using System; using System.Collections.Generic; class Demo { static void Main(String[] args) { List<int> list = new List<int>(); list.Add(20); list.Add(40); list.Add(60); list.Add(80); foreach (int val in list) { Console.WriteLine(val); } int a = list[0]; Console.WriteLine("First element: "+a); } }