My Report

C# LINQ Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Can we use linq to query against a DataTable?

2. Choose the wrong statement about the LINQ?

3. What will be the output of the following C# 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 > -5 && n < 6
                       orderby n descending
                       select n;
        Console.Write("The positive values in nums: ");
        foreach (int i in posNums) Console.Write(i + " ");
        Console.WriteLine();
        Console.ReadLine();
    }
}

4. Select the namespace which should be included while making use of LINQ operations?

5. What will be the output of the following C# 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 % 2 ==0
                       select n;
            Console.Write("The positive values in nums: ");
            foreach (int i in posNums) Console.Write(i + " ");
            Console.WriteLine();
            Console.ReadLine();
        }
    }

6. What will be the output of the following C# 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();
    }
}

7. What will be the output of the following C# code snippet?

class Program
{
    static void Main(string[] args)
    {
        int[] nums = {1};
        var posNums = from n in nums
                      wheres n > 0 
                     select Math.Max(78, 9);
        Console.Write("The largest values in nums: ");
        foreach (int i in posNums) Console.Write(i + " ");
        Console.WriteLine();
        Console.ReadLine();
    }
}

8. Choose the namespace in which the interface IEnumerable is declared?

9. What will be the output of the following C# 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();
    }
}

10. Assume 2 columns named as Product and Category how can be both sorted out based on first by category and then by product name?


 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.