I have a function that takes "params string[] requested" as input and is supposed to use readline to get input from the user and see if any match and if anything matches then return what matches
static string inputCheck(params string[] requested){
string? userInput = Console.ReadLine();
IEnumerable<string> selected = requested.Where(n => n == userInput);
if (selected != null) return selected; //Error is here
return "Nothing Please Try again";
}
The error I get is "Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'string' (csharp0029)"
I would prefer a solution that uses linq
if(requested.Any(x => x == userInput)) return userInput;? And FYIWhereis never going to returnnull.selectedis a collection of strings. If you want to return a single string, how will you determine which one in the collection to return?selected.First()or.FirstOrDefault()Wherewill return them all but it will never benull. It will be empty (which you can check for withif (selected.Any()) return selected)