Hello wondering if there is an easier way to display odd / even numbers.
I know I could do a for loop and load a list. Then I can write another for loop
to loop through the list and check if a value is odd / even:
for(i=0; i<100; i++)
if(myList[i]%2==0) //even
//do something
else
//odd do something
But is there any way to shorten this up just so that I can easily get a list of odd or even numbers. Not homework just wondering.
Could you use some sort of lambdas:
The Enumerable just loads the list with 1-100, and then I simply snatch all odds / evens and then print them. This all can be shortened to:
e,o have an implicit type var. The compiler can determine its type so these two lines are equivalent to:
Then to find the odds / evens directly to a list type:
And to print it is listed in my initial code.