My Report

C# Programming Mock Test 8


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

Question 1 of 10

1. Select the Keyword which supports the run time type identification?

Question 1 of 10

Question 2 of 10

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

Question 2 of 10

Question 3 of 10

3. A HashTable t maintains a collection of names of states and capital city of each state. Which among the following finds out whether "New delhi" state is present in the collection or not?

Question 3 of 10

Question 4 of 10

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

Question 4 of 10

Question 5 of 10

5. 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");
    }
}

Question 5 of 10

Question 6 of 10

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

 class Program
 {
     static void Main(string[] args)
     {
         double x = 4.772;
         double y = 4.76;
         double z = Math.Max(x, y);
         Console.WriteLine(z);
         Console.ReadLine();
     }
 }

Question 6 of 10

Question 7 of 10

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

Question 7 of 10

Question 8 of 10

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

Question 8 of 10

Question 9 of 10

9. In the following C# code, which statements are perfectly valid?

public class Csharp
{
    public void subject<S>(S arg)
    {
        Console.WriteLine(arg);
    }
}
class Program
{
    static Void Main(string[] args)
    {
        Csharp c = new Csharp();
        c.subject("hi");
        c.subject(20);
    }
}

Question 9 of 10

Question 10 of 10

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

Question 10 of 10


 

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.