ইতিমধ্যে তৈরি করা তালিকায় একটি আইটেম সন্নিবেশ করতে, সন্নিবেশ() পদ্ধতি ব্যবহার করুন৷
৷প্রথমত, উপাদান সেট করুন -
List <int> list = new List<int>(); list.Add(989); list.Add(345); list.Add(654); list.Add(876); list.Add(234); list.Add(909);
এখন, ধরা যাক আপনাকে ৪র্থ অবস্থানে একটি আইটেম সন্নিবেশ করতে হবে। এর জন্য, Insert() পদ্ধতি -
ব্যবহার করুন// inserting element at 4th position list.Insert(3, 567);
আসুন সম্পূর্ণ উদাহরণ দেখি -
উদাহরণ
using System;
using System.Collections.Generic;
namespace Demo {
public class Program {
public static void Main(string[] args) {
List < int > list = new List < int > ();
list.Add(989);
list.Add(345);
list.Add(654);
list.Add(876);
list.Add(234);
list.Add(909);
Console.WriteLine("Count: {0}", list.Count);
Console.Write("List: ");
foreach(int i in list) {
Console.Write(i + " ");
}
// inserting element at 4th position
list.Insert(3, 567);
Console.Write("\nList after inserting a new element: ");
foreach(int i in list) {
Console.Write(i + " ");
}
Console.WriteLine("\nCount: {0}", list.Count);
}
}
}