Contains for HashSet - C#
Формулировка задачи:
Приветствую! Не находит слово: "Москв"
Кто знает почему? Заранее спасибо.
HashSet<string> totalCity = new HashSet<string>();
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
totalCity.Add(s);
Console.WriteLine(s);
}
}
if(totalCity.Contains("Москв"))
{
Console.WriteLine("аааа");
}Решение задачи: «Contains for HashSet»
textual
Листинг программы
HashSet<string> totalCity = new HashSet<string>();
using (var sr = File.OpenText(dir))
{
string s;
while ((s = sr.ReadLine()) != null)
totalCity.Add(s);
foreach (var city in totalCity)
if (city.IndexOf("Москв", StringComparison.InvariantCultureIgnoreCase) >= 0)
Console.WriteLine(city);
}