Trying to determine if my list of integer is made of odd or even numbers, my desired output is a list of true an/or false. Can I perform the following operation on the list lst or do I need to create a loop? A is the output.
List <int> lst = new List <int>(); A = IsOdd(lst);
You could try using Linq to project the list:
var output = lst.Select(x => x % 2 == 0).ToList();
This will return a new list of bools such that {1, 2, 3, 4, 5} will map to {false, true, false, true, false}.
{1, 2, 3, 4, 5}
{false, true, false, true, false}
1.4m articles
1.4m replys
5 comments
57.0k users