Vidyalelo
C# Programming · all questions

LINQ (Language
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

85

Questions

3/5

Page

Pick an option on a question to see the right answer and solution.

Which LINQ operator is used to return a specified number of contiguous elements from the end of a sequence?

Select an option to see the answer and solution.

In LINQ, what does the Reverse operator do?

Select an option to see the answer and solution.

What is the purpose of the Zip operator in LINQ?

Select an option to see the answer and solution.

Which LINQ operator is used to return elements from a sequence until a specified condition becomes false?

Select an option to see the answer and solution.

In LINQ, what does the ElementAtOrDefault operator do?

Select an option to see the answer and solution.

Can we use linq to query against a DataTable?

Select an option to see the answer and solution.

Which operator among the following supplies the information about the characteristics of a typeof?

Select an option to see the answer and solution.

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 = 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();
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class B { }
class A : B { }
class Program
{
    static void Main(string[] args)
    {
        A a = new A();
        B b = new B();
        if (a is A) 
        Console.WriteLine("a is an A");
        if (b is A)
        Console.WriteLine("b is an A because it is derived from A");
        if (a is B)
        Console.WriteLine("This won’t display -- a not derived from B");
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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 = 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();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class UseTypeof 
{
    static void Main() 
    {
        Type t = typeof(StreamReader);
        Console.WriteLine(t.FullName);
        if(t.IsClass) Console.WriteLine("Is a class.");
        if(t.IsAbstract) Console.WriteLine("Is abstract.");
        else Console.WriteLine("Is concrete.");
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
static void Main(string[] args)
{
    int[] nums = { 5, 4, 6, 3, 14, 9, 8, 17, 1, 24, -1, 0 };
    Array.Sort(nums);
    int idx = Array.BinarySearch(nums, 14);
    if (idx == 9)
    {
        Console.WriteLine(Convert.ToBoolean(1));
    }
    else
   {
       Console.WriteLine(Convert.ToBoolean(0));
   }
   Console.WriteLine("Index of 14 is " + idx);
   Console.ReadLine();
}

Select an option to see the answer and solution.

Choose the namespace in which Expression trees are encapsulated?

Select an option to see the answer and solution.

Which mechanism among the following helps in identifying a type during the execution of a program?

Select an option to see the answer and solution.

In the following C# code, 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();
    }
}

Select an option to see the answer and solution.

Choose the correct statement about the IComparer interface in C#?

Select an option to see the answer and solution.

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();
    }
}

Select an option to see the answer and solution.

What does the following property defined in the array class defines in C#?
public bool IsReadOnly { get; }

Select an option to see the answer and solution.