I´ve done a school homework where we need to be able to search in our program (console app).
I´ve created an object (Sodacrate) which contains an array of objects (sodabottles) which have an index length of 24. The sodabottles have name, price and type variables We can not use LISTS for this according to our teacher (probably because he want´s us to find other ways to solve this), that´s the reason for an array containing objects.
When I´m searching I can search for the exact name of the sodabottle, or I can search for the first letter. If I for example have a bottle of Coca Cola (exact spelling) and I´m searching for coca, then I won´t find a match. If I search for c, C or Coca or even Coca Cola I´ll find a match.
How do I make the searchresult convert ToLower? I´ve tried this and also searched the problem, but didn´t find any clear solutions.
It gives me an compiling error
Error CS0029 Cannot implicitly convert type 'string' to 'System.Collections.Generic.IEnumerable' thesodacrate C:\Users\Benny\source\repos\thesodacrate\thesodacrate\Sodacrate.cs 244 Active
I´m sorry if this seems like simple thing, but I´m almost getting bald over this. I also need to say that this is a whole new territory for me, and I´m mostly doing trial and error to figure this out.
I´ve edited the code so it´s up to date how it looks atm. entries = entries on row 7 creates the compiling error.
Console.Write("Type in your search: ");
var keyword = Console.ReadLine();
keyword = keyword.ToLower();
Console.WriteLine(keyword);
var entries = bottles.Where(entry => entry.SodaBottleName !=null && entry.SodaBottleName.Contains(keyword));
entries = entries.ToString().ToLower();
if (entries.Count() == 0)
{
Console.Write("Didn´t find any match");
Console.WriteLine("Press enter to return to mainmenu");
}
else
{
foreach (var entry in entries)
{
Console.WriteLine("{0} - {1} $", entry.SodaBottleName, entry.SodaBottlePrice);
}
Console.WriteLine("You´ve added {0} bottles that match your search: {1}.", entries.Count(), keyword);
Console.WriteLine("Press enter to return to mainmenu");
}
Console.ReadLine();