adplus-dvertising
frame-decoration

Question

What will be the output of given code snippet?
class Program
 {
     static void Main(string[] args)
     {
         int[] nums = { 1, -2, 3, 0, -4, 5};
         var posNums = from n in nums
                       where n >= 0
                       select n;
        foreach (int i in posNums) 
        Console.Write(i + " ");
        Console.WriteLine();
        Console.ReadLine();
    }
}

a.

0, 1, -2, -4, 5

b.

1, 3, 0, 5

c.

1, 3, 5

d.

Run time error

Posted under LINQ C# programming

Answer: (b).1, 3, 0, 5

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What will be the output of given code snippet?