Question 21: What will be the output of the following program?
public class Program
{
public static void Main(string[] args)
{
for(int i=0;i<2;i++)
Printer.Print(i);
}
}
public static class Printer
{
static Printer()
{
Console.Write("-constructor-.");
}
public static void Print(object o)
{
Console.Write(o);
}
}
Question 22: What will be the output of the following program?
public static void Main(string[] args)
{
test();
}
void test(){
Console.Write("test()");
}
Question 23: What will be the output of the following program?
class Program
{
static void Main()
{
Person p = new Person() {
FirstName = "James",
LastName = "Bond"
};
Console.Write(p.ToString());
}
}
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public override string ToString() => $"{FirstName} {LastName}";
}
Question 24: What will be the output of the following program?
using static System.String;
class Program
{
static void Main()
{
string str = null;
Console.Write(IsNullOrEmpty(str));
Console.ReadKey();
}
}
Question 25: What does the following code do?
namespace Business
{
public static class BusinessRules
{
public static bool Compare(this string str, string value)
{
return str == value;
}
}
}