My Report

C# Programming Practice 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

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

2. Which among the given statements are correct about the Stack collection?

3. Which among the given classes provides types of rounding functions?

4. What does the following property defined in the array class defines in C#?

 public bool IsReadOnly { get; }

5. Which feature enables to obtain information about the use and capabilities of types at runtime?

6. Which method will be used to copy content from one array to another array?

7. Which of the following statements are valid in the following C# code snippet?

public class Generic<T>
{
    public T Field;
    public void testSub()
    {
        T i = Field + 1;
    }
}
class Program
{
    static void Main(string[] args)
    {
        Generic<int>g = new Generic<int>();
        g.testSub();
    }
}

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

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

public class Generic<T>
{
    Stack<T> stk = new Stack<T>();
    public void push(T obj)
    {
        stk.Push(obj);
    }
    public T pop()
    {
        T obj = stk.Pop();
        return obj;
    }
}
class Program
{
    static void Main(string[] args)
    {
        Generic<string> g = new Generic<string>();
        g.push("C++");
        Console.WriteLine(g.pop() + " ");
        Generic<int> g1 = new Generic<int>();
        g1.push(20);
        Console.WriteLine(g1.pop());
        Console.ReadLine();
    }
}

10. Which is the correct statement about an ArrayList collection that implements the IEnumerable interface?


 

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.