কম্পিউটার টিউটোরিয়াল

C#-এ StringCollection-এ নির্দিষ্ট অবজেক্টের সূচক খুঁজে বের করা


C#-এ StringCollection ক্লাসে নির্দিষ্ট স্ট্রিং অবজেক্টের সূচক (index) পেতে IndexOf() মেথড ব্যবহার করা হয়। এটি প্রথম মিলের শূন্য-ভিত্তিক সূচক ফেরত দেয়।

উদাহরণ ১

using System;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        StringCollection strCol = new StringCollection();
        strCol.Add("Accessories");
        strCol.Add("Books");
        strCol.Add("Electronics");
        strCol.Add("Books");
        
        Console.WriteLine("StringCollection উপাদানগুলো...");
        foreach (string res in strCol) {
            Console.WriteLine(res);
        }
        
        strCol.Insert(2, "Headphone");
        Console.WriteLine("StringCollection উপাদানগুলো... আপডেটেড");
        foreach (string res in strCol) {
            Console.WriteLine(res);
        }
        
        Console.WriteLine("নির্দিষ্ট অবজেক্ট 'Electronics'-এর সূচক = " + strCol.IndexOf("Electronics"));
    }
}

আউটপুট

StringCollection উপাদানগুলো...
Accessories
Books
Electronics
Books
StringCollection উপাদানগুলো... আপডেটেড
Accessories
Books
Headphone
Electronics
Books
নির্দিষ্ট অবজেক্ট 'Electronics'-এর সূচক = 3

উদাহরণ ২

অন্য একটি উদাহরণ:

using System;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        StringCollection stringCol = new StringCollection();
        String[] arr = new String[] { "100", "200", "300", "400", "500" };
        
        Console.WriteLine("Array উপাদানগুলো...");
        foreach (string res in arr) {
            Console.WriteLine(res);
        }
        
        stringCol.AddRange(arr);
        Console.WriteLine("নির্দিষ্ট স্ট্রিংটি StringCollection-এ আছে কি? = " + stringCol.Contains("800"));
        Console.WriteLine("মোট উপাদানের সংখ্যা = " + stringCol.Count);
        Console.WriteLine("StringCollection দিয়ে পুনরাবৃত্তি = " + stringCol.Count);
        
        StringEnumerator myenum = stringCol.GetEnumerator();
        while (myenum.MoveNext())
            Console.WriteLine(myenum.Current);
        
        Console.WriteLine("নির্দিষ্ট অবজেক্ট '500'-এর সূচক = " + stringCol.IndexOf("500"));
        Console.WriteLine("নির্দিষ্ট অবজেক্ট '1000'-এর সূচক = " + stringCol.IndexOf("1000"));
    }
}

আউটপুট

Array উপাদানগুলো...
100
200
300
400
500
নির্দিষ্ট স্ট্রিংটি StringCollection-এ আছে কি? = False
মোট উপাদানের সংখ্যা = 5
StringCollection দিয়ে পুনরাবৃত্তি = 5
100
200
300
400
500
নির্দিষ্ট অবজেক্ট '500'-এর সূচক = 4
নির্দিষ্ট অবজেক্ট '1000'-এর সূচক = -1

  1. C#-এ SortedList-র নির্দিষ্ট ইনডেক্সের উপাদান মুছে ফেলা

  2. C#-তে Collection-এ নির্দিষ্ট সূচক 위치한 উপাদান সরানো

  3. C#-এ SortedSet অবজেক্ট প্রপার সুপারসেট কিনা তা যাচাই করুন

  4. C#-এ SortedSet অবজেক্ট প্রপার সাবসেট কিনা তা যাচাই করুন