BinarySearch 메서드를 사용하여 배열 요소의 위치를 가져옵니다.
문자열 배열 설정 -
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