- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Array.BinarySearch Method in C#
Get the location of array elements using the BinarySearch method.
Set a string array −
string[] str = { "a", "m", "i", "t"};
Now get the location of character ‘t’ using Array.BinarySearch −
Array.BinarySearch(str, "t");
Here is the complete code −
Example
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); } }
Output
Index : 3
Advertisements