Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Binary Search for String in C#

  1. using System;
  2.  
  3. namespace BinarySearchUsingString
  4. {
  5. public class Program
  6. {
  7. public static void Main(string[] args)
  8. {
  9. //Your code goes here
  10.  
  11. string[] data = new string[]{"Forget", "Code", "Prasanna", "Senthil" };
  12. string inputString = Console.ReadLine();
  13. int index = Array.BinarySearch<string>(data, inputString,StringComparer.OrdinalIgnoreCase);
  14. if(index > -1){
  15. Console.WriteLine("Search String ["+inputString+"] found location at "+index);
  16. }else{
  17. Console.WriteLine("Search String ["+inputString+"] is not found!");
  18. }
  19.  
  20. }
  21. }
  22. }