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

4/5

Page

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

Choose the namespace in which the interface IEnumerable is declared?

Select an option to see the answer and solution.

Select the Keyword which supports the run time type identification?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
static void Main() 
{
    int[] nums = { 1, 2, 3, 4, 5 };
    Console.Write("Original order: ");
    foreach(int i in nums)
    Console.Write(i + " ");
    Array.Reverse(nums);
    Console.Write("Reversed order: ");
    foreach(int i in nums)
    Console.Write(i + " ");
    Console.WriteLine();
}

Select an option to see the answer and solution.

Choose the wrong statement about the LINQ?

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 = from n in nums
                      where n >= 0
                      select n;
       foreach (int i in posNums) 
       Console.Write(i + " ");
       Console.WriteLine();
       Console.ReadLine();
   }
}

Select an option to see the answer and solution.

Select the interfaces implemented by array class.

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

Select an option to see the answer and solution.

Select the class which is the base class for all arrays 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, -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();
       }
}

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

Select an option to see the answer and solution.

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

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

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class A {}
class B : A {}
class CheckCast 
{
    static void Main() 
    {
        A a = new A();
        B b = new B();
        b = a as B;
        b = null;
        if(b==null)
        Console.WriteLine("The cast in b = (B) a is NOT allowed.");
        else
        Console.WriteLine("The cast in b = (B) a is allowed");
    }
}

Select an option to see the answer and solution.

Select the statement which are correct about RTTI(Runtime type identification)?

Select an option to see the answer and solution.

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

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)
{
    string[] strings = {"beta", "alpha", "gamma"};
    Console.WriteLine("Array elements: ");
    DisplayArray(strings);
    Array.Reverse(strings); 
    Console.WriteLine("Array elements now: ");
    DisplayArray(strings);
    Console.ReadLine();
 }
 public static void DisplayArray(Array array)
 {
     foreach (object o in array)
     {
         Console.Write("{0} ", o);
     }
         Console.WriteLine();
}

Select an option to see the answer and solution.

What does the following C# code signify?
expr is type

Select an option to see the answer and solution.

Which operator among the following is used to perform the operation of boxing, unboxing, reference and identity conversions?

Select an option to see the answer and solution.

What does the following property define in C#?
public static int BinarySearch<T>(T[] array, int index, int length, T value)

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

Select an option to see the answer and solution.