What will be the output of the following C# code snippet?
static void Main(string[] args)
{
int[] nums = { 5, 4, 6, 3, 14, 9, 8, 17, 1, 24, -1, 0 };
Array.Sort(nums);
int idx = Array.BinarySearch(nums, 14);
if (idx == 9)
{
Console.WriteLine(Convert.ToBoolean(1));
}
else
{
Console.WriteLine(Convert.ToBoolean(0));
}
Console.WriteLine("Index of 14 is " + idx);
Console.ReadLine();
}
static void Main(string[] args)
{
int[] nums = { 5, 4, 6, 3, 14, 9, 8, 17, 1, 24, -1, 0 };
Array.Sort(nums);
int idx = Array.BinarySearch(nums, 14);
if (idx == 9)
{
Console.WriteLine(Convert.ToBoolean(1));
}
else
{
Console.WriteLine(Convert.ToBoolean(0));
}
Console.WriteLine("Index of 14 is " + idx);
Console.ReadLine();
}
A. TRUE
0
B. Run time error
C. TRUE
9
D. None of the mentioned
Answer: Option C
Join The Discussion