Consider the following program.

using System;
using System.Collections;

namespace Infosys.TelephoneDirectory
{
class Program
{
static void Main(string[] args)
{
SortedList myPhoneBook = new SortedList();
myPhoneBook.Add("Pat", 9932001343);
myPhoneBook.Add("Ted", 8956412745);
myPhoneBook.Add("Sam", 9243761256);
myPhoneBook.Add("Ann", 9546300876);

Console.WriteLine("Please enter a name to display the details:");
string searchName = Console.ReadLine();
int flag = 0;
foreach (object name in myPhoneBook.Keys)
{
//String.Compare(string str1,string str2,bool ignoreCase) method
//is used here for case insensitive comparison

if (String.Compare(name.ToString(), searchName, true) == 0)
{
Console.WriteLine("Search Results are:");

// LINE 01 : Code to display the output

flag = 1;
break;
}
}
if (flag == 0)
Console.WriteLine("No contacts found!");
}
}
}

Choose the correct option that needs to be written at LINE 01 inside Main() method in order to achieve the following output, when the user enters "Ted" as the input?

Please enter a name to display the details:
Ted
Search Results are:
Contact Name : Ted
Contact No. : 8956412745

Console.WriteLine("Contact Name : " + name);
                    Console.WriteLine("Contact No.  : " + myPhoneBook.GetKey(0).ToString());
Console.WriteLine("Contact Name : " + name.ToString());
          Console.WriteLine("Contact No.  : " + myPhoneBook[name.ToString()]);
Console.WriteLine("Contact Name : " + name.Key);
          Console.WriteLine("Contact No.  : " + myPhoneBook[name.Key]);
Console.WriteLine("Contact Name : " + name.Key);
          Console.WriteLine("Contact No.  : " + name.Value);
Correct Option - b

To get all Infosys Certified L1 Junior Microsoft .NET Programmer Exam questions Join Group https://bit.ly/infy_premium_group

We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.

Qtr No. 213, New Town Yehlanka Indore 454775

admin@prepflix.in