I'm still getting acquainted with delegates and lambdas, I'm not using LINQ, and I also only discovered the ConvertAll function today, so I'm experimenting and asking this to bolster my understanding.
The task I had was to establish whether a string of numbers were even or odd. So first, convert the string list to an int list, and from there into a bool list. As bloated as the code would be, I wondered if I could get it all on one line and reduce the need for an extra for loop.
string numbers = "2 4 7 8 10";
List<bool> evenBools = new List<bool>(Array.ConvertAll(numbers.Split(' '), (x = Convert.Int32) => x % 2 == 0))
The expected result is [true, true, false, true, true]. Obviously the code doesn't work.
I understand that the second argument of Array.ConvertAll) requires the conversation to take place. From string to int, that's simply Convert.ToInt32. Is it possible to do that on the fly though (i.e. on the left side of the lambda expression), so that I can get on with the bool conversion and return on the right?
=>is only ever a list of parameters, possibly in parentheses, possibly using implicit typing. It's not clear what you expectedx = Convert.Int32to mean there, but you should reset your expectations of what can appear to the left hand side of=>.Array.ConvertAll<>in you case (but it is possible). You could dovar evenBools = numbers.Split(' ').Select(x => Convert.ToInt32(x) % 2 == 0).ToList();