adplus-dvertising
frame-decoration

Question

Select the output for given code snippet:
class Program
{
    static void Main(string[] args)
    {
        int[] nums = { 16,  9, 25};
        var posNums = from n in nums
                      where n > 0 
                      select Math.Sqrt(n);
 
        Console.Write("The positive values in nums: ");
        foreach (int i in posNums) Console.Write(i + " ");
        Console.WriteLine();
        Console.ReadLine();
    }
}

a.

Code runs successfully prints nothing

b.

Code runs successfully prints required output

c.

Run time error

d.

Compile time error

Posted under LINQ C# programming

Answer: (b).Code runs successfully prints required output

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Select the output for given code snippet: