After some advice, which method do you think is better to use when searching a dictionary for the matching value(s)?
Method One
Console.WriteLine("ENTER A PERSON/NUMBER TO SEARCH FOR");
string input = Console.ReadLine().ToUpper();
bool found = false;
if (myPhoneBook.ContainsKey(input)) // used with a persons name and returns number
{
Console.WriteLine(myPhoneBook[input]);
found = true;
}
if (!(myPhoneBook.ContainsKey(input))) //searches the number and returns the name
{
var searchingfornumbers = from num in myPhoneBook
where num.Value == input
select num.Key;
foreach(var person in searchingfornumbers)
{
Console.WriteLine(person);
found = true;
}
}
if(found == false)
{
Console.WriteLine("NO RECORD FOUND");
}
Method Two
Console.WriteLine("ENTER A PERSON/NUMBER TO SEARCH FOR");
string input = Console.ReadLine();
bool found = false;
var query0 = from person in myPhonebook //searches for the number, returns name
where person.Value == input
select person.Key;
foreach(var person in query0)
{
Console.WriteLine(person);
found = true;
}
var query1 = from person in myPhonebook //searches for the name, returns numbers
where person.Key == input
select person.Value;
foreach (var person in query1)
{
Console.WriteLine(person);
found = true;
}
if(found == false)
{
Console.WriteLine("NO RECORD FOUND");
}
Console.ReadKey();