Program to find all elements of an array less than 10. [Resolved]

Posted by Amatya under Error and Solution on 3/11/2017 | Points: 10 | Views : 235 | Status : [Member] | Replies : 1

Program to find all elements of an array less than 10.

public void DNF() 
{
int[] dnfNum = { 10, 52, 3, 4, 5, 20, 7, 6, 1, 0, 21,100 };

var dnflowNum =
from n in dnfNum
where n < 10
select n;

Console.WriteLine("Values less then 10-->");
foreach (var x in dnflowNum )
{
Console.WriteLine(x);
}
}


Thanks
Amatya

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks



Responses

Posted by: Rajnilari2015 on: 3/11/2017 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Can also be done as

new int[] { 10, 52, 3, 4, 5, 20, 7, 6, 1, 0, 21, 100 }.Where(i => i < 10).ToList().ForEach(i => Console.WriteLine(i));


OR

Array.ForEach

(
new int[] { 10, 52, 3, 4, 5, 20, 7, 6, 1, 0, 21, 100 }, element =>
{
if(element<10) Console.WriteLine(element);
}
);


--
Thanks & Regards,
RNA Team

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response