C# Test 5

More C# Tests

Question 1: What will be the output of the following C# 7 code?

int Sixteen =   0b0001_0000;
Console.WriteLine(Sixteen);

Question 2: Which of the following can contain event declarations?

Question 3: What will be the output of the following program?

static void Main(string[] args)
{
    Action<int> DoSomething = i => Console.Write(i);
       
    DoSomething(50);
}

Question 4: Which of the following statement is TRUE?

Question 5: Which of the following can be defined generic?

Question 6: Which of the following generic constraints restricts the generic type parameter to an object of the class?

Question 7: Interface members are ______ by default.

Question 8: What to do if a class implements two interfaces which coincidently have one method with the same name and signature?

Question 9: Can one interface inherit from one or multiple interfaces in C#?

Question 10: What will be the output of the following program?

class Shape
{
    protected int Sides { get; set; }
       
}

class Square : Shape
{
    public int GetSides()
    {
        return this.Sides;
    }
}

Shape sq = new Square();
sq.Sides = 4;

Question 11: What will be the output of the following program?

class Person
{
    public void Introduction(int age, string name){ 
        Console.WriteLine("My name is " + name);
    }
        
    public void Introduction(string name, int age=0){ 
        Console.WriteLine($"My name is {name} and I am {age} years old");
    }      
}
Person p = new Person();
p.Introduction("Steve");

Question 12: What will be the output of the following program?

class Printer
{
    public virtual void Install()
    {
        Console.WriteLine("Printer Installed.");
    }

    public virtual void Print(string text)
    {
        Console.WriteLine("Printing: " + text);
    }
}

class LaserPrinter : Printer
{
    public void Install()
    {
        Console.WriteLine("Laser Printer Installed Successfully.");
    }
        
}

Printer myprnt = new LaserPrinter();
myprnt.Install();

Question 13: Which of the following static class will you use for file I/O operations?

Question 14: Which of the following class is the base class for all I/O operations from different sources?

Question 15: What will be the output of the following C# 7.0 code?

public class Program
{
	public static void Main()
	{
		var input = "100";
		if (int.TryParse(input, out int result))
			Console.WriteLine(result);
		else
			Console.WriteLine("Could not parse input");
	}
}