If you are a c# beginner or want to start learning the c# programming language, then this program will help you to understand the basics of c# programming. In this program, we are going to share C# program to perform searching using predefined functions with the output.
Copy the below c# program and execute it in your Microsoft Visual Studio IDE (Integrated Development Environment ).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | using System; class linSearch { public static void Main() { Console.WriteLine("Enter Number of Elements you Want to Hold in the Array ? "); string s = Console.ReadLine(); int x = Int32.Parse(s); int[] a = new int[x]; Console.WriteLine("Enter Array Elements :"); for (int i = 0; i < x; i++) { string s1 = Console.ReadLine(); a[i] = Int32.Parse(s1); } Array.Sort(a); Console.WriteLine("Sorted Array : "); for (int i = 0; i < x; i++) { Console.WriteLine("{0}", a[i]); } Console.WriteLine("Enter the Element to be Searched : "); string s3 = Console.ReadLine(); int x2 = Int32.Parse(s3); int x3 = Array.BinarySearch(a, (Object)x2); Console.WriteLine("BinarySearch: " + x3); Console.WriteLine("Element {0} is {1}", x3, a[x3]); Console.Read(); } } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.