बाइनरीसर्च पद्धति का उपयोग करके सरणी तत्वों का स्थान प्राप्त करें।
एक स्ट्रिंग सरणी सेट करें -
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