BinarySearch পদ্ধতি ব্যবহার করে অ্যারে উপাদানের অবস্থান পান।
একটি স্ট্রিং অ্যারে সেট করুন −
string[] str = { "a", "m", "i", "t"}; এখন Array.BinarySearch -
ব্যবহার করে 't' অক্ষরের অবস্থান পানArray.BinarySearch(str, "t");
এখানে সম্পূর্ণ কোড −
উদাহরণ
using System;
using System.Text;
public class Demo {
public static void Main() {
string[] str = { "a", "m", "i", "t"};
// Using BinarySearch method to get location of character 't'
int res = Array.BinarySearch(str, "t");
// displaying the location
Console.WriteLine("Index : "+res);
}
} আউটপুট
Index : 3