0

I am not getting why this code of Words is not running

using System; using System.Collections.Generic; namespace Code_Coach_Challenge { class Program { static void Main(string[] args) { string[] words = { "home", "programming", "victory", "C#", "football", "sport", "book", "learn", "dream", "fun" }; string letter = Console.ReadLine(); int count = 0; int y=1; while (count < 9) { if(words[count].Contains(letter)) { Console.WriteLine(words[count]); y+=count; }if(y==0||y==1) {Console.WriteLine("No match");} } //your code goes here } } } }

22nd Feb 2022, 8:04 AM
Bhagyashri Agrawal
1 Answer
+ 1
Use foreach loop instead, more readable, I think ... string letter = Console.ReadLine(); int count = 0; foreach( string item in words ) { if( item.Contains( letter ) ) { Console.WriteLine( item ); count++; } } if( count == 0 ) { Console.WriteLine( "No match" ); }
22nd Feb 2022, 8:58 AM
Ipang