C# Program to Search an Item in an Array Using Binary Search

C# Program to Search an Item in an Array Using Binary Search The article is a lively article because it contains interesting information and your favorite.   

C# Program to Search an Item in an Array Using Binary Search

C# Program to Search an Item in an Array Using Binary Search

//Program to search an item in an array 
//using binary search in C#.

using System;

class Demo
{
    public static void SearchItem(int []array, int item)
    {
        int itemAtIndex = Array.BinarySearch(array, 0, array.Length, item);

        if (itemAtIndex >= 0)
        {
            Console.WriteLine("Item "+item+" found at index "+itemAtIndex);
        }
        else 
        {
            Console.WriteLine("Item does not found");
        }
    }

    public static void Main()
    {
        int[] intArray = { 012,123, 345,456, 786};

        SearchItem(intArray, 786);
    }    
}
Item 786 found at index 4
Press any key to continue . . .

Final Words

I hope you find the article C# Program to Search an Item in an Array Using Binary Search uses. The reason is that we have told you all the information through this article in a way that you can understand. And if you have any doubts, you can express your doubts through the comment box. We also ask that you help share this article with your friends.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment