adplus-dvertising

Welcome to the LINQ MCQs Page

Dive deep into the fascinating world of LINQ with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of LINQ, a crucial aspect of C# programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of LINQ, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C# programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through LINQ. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C# programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of LINQ. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

LINQ MCQs | Page 2 of 2

Q11.
What will be the output of the given code snippet?
class Program
{
    static void Main(string[] args)
    {
        string[] strs = {"alpha", "beta", "gamma"};
        var chrs = from str in strs
                   let chrArray = str.ToCharArray()
                   from ch in chrArray
                   orderby ch
                   select ch;
        Console.WriteLine("The individual characters in sorted order:");
        foreach (char c in chrs) 
        Console.Write(c + " ");
        Console.WriteLine();
        Console.ReadLine();
    }
}
Discuss
Answer: (b).a a a a a b e g h l m m p t
Q12.
What will be the output of the given code snippet?
class Program
 {
     static void Main(string[] args)
     {
         int[] nums = { 1, -2, 3, 0, -4, 5 };
         var posNums = nums.Where(n => n > 0).Select(r => r*2).OrderByDescending(r=>r);
         Console.Write("The positive values in nums: ");
         foreach(int i in posNums) 
         Console.Write(i + " ");
         Console.WriteLine();
         Console.ReadLine();
     }
 }
Discuss
Answer: (c).code run successfully prints multiple of 2
Q13.
What will be the output of the given code snippet?
class Program
 {
     static void Main(string[] args)
     {
         int[] nums = {3, 1, 2, 5, 4};
         var ltAvg = from n in nums
                     let x = nums.Average()
                     where n < x
                     select n;
         Console.WriteLine("The average is " + nums.Average());
         Console.ReadLine();
     }
 }
Discuss
Answer: (b).3
Q14.
What will be the output of the given code snippet?
class Program
{
    static void Main(string[] args)
    {
        Expression<Func<int, int, bool>>
        IsFactorExp = (n, d) => (d != 0) ? (n % d) == 0 : false;
        Func<int, int, bool> IsFactor = IsFactorExp.Compile();
        if (IsFactor(10, 5))
        Console.WriteLine("5 is a factor of 10.");
        if (!IsFactor(343, 7))
        Console.WriteLine("7 is not a factor of 10.");
        Console.ReadLine();
    }
}
Discuss
Answer: (d).5 is a factor of 10
Q15.
Choose the namespace in which Expression trees are encapsulated:
Discuss
Answer: (b).System.Linq.Expressions
Q16.
For the given set of codes, which query will work according to the set of code?
class Program
{
    static void Main(string[] args)
    {
        int[] nums = { 1, -2, 3, 0, -4, 5 };
        int len = /*_________________ */
        Console.WriteLine("The number of positive values in nums: " + len);
        Console.ReadLine();
    }
}
Discuss
Answer: (c).(from n in nums where n > 0
select n).Count();
Q17.
For the given set of code, what does the output represent?
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;
        int len = posNums.Count();
        Console.WriteLine(len);
        Console.ReadLine();
    }
}
Discuss
Answer: (c).Execution of code with counting total numbers greater than zero
Q18.
For the given set of codes, what is the output?
class Program
 {
     static void Main(string[] args)
     {
         int[] nums = { 1, -2, 3, 0, -4, 5 };
         var posNums = nums.Where(n => n < 10).Select(r => r%3);
         Console.Write("The values in nums: ");
         foreach (int i in posNums) Console.Write(i + " ");
         Console.WriteLine();
         Console.ReadLine();
     }
 }
Discuss
Answer: (c).1 -2 0 0 -1 2
Q19.
For the given set of codes, what is the output?
class Program
{
    static void Main(string[] args)
    {
        string[] strs = { ".com", ".net", "facebook.com", "google.net", "test", "netflix.net", "hsNameD.com" };
        var netAddrs = from addr in strs
                       where addr.Length > 4 && addr.EndsWith(".net",
                       StringComparison.Ordinal)
                       select addr;
        foreach (var str in netAddrs) Console.WriteLine(str);
        Console.ReadLine();
    }
}
Discuss
Answer: (d).google.net
netflix.net
Q20.
For the given set of codes, what is the output?
class Program
    {
        static void Main(string[] args)
        {
 
            int[] nums = { 1, -2, -3, 5 };
            var posNums = from n in nums
                          orderby n descending
                          select n*4 / 2;
            Console.Write("The values in nums: ");
            foreach (int i in posNums) Console.Write(i + " ");
            Console.WriteLine();
            Console.ReadLine();
        }
    }
Discuss
Answer: (a).10 2 -4 -6
Page 2 of 2

Suggested Topics

Are you eager to expand your knowledge beyond C# programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!