C# DataType MCQs

Question 31: What will the output of the following program?

public static void Main(string[] args)
{
	object o1 = "csharp";  
    char[] arr = {'c','s','h','a','r','p'};  
    object o2 = new string(arr);   

	Console.Write(o1 == o2);
	Console.Write(o1.Equals(o2));
}

Question 32: What will be the output of the following code?

int? x = null;
int y = x ?? -1;

Console.Write(y);

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

object obj = "hello";
Type t1 = typeof(obj); 
Type t2 = obj.GetType();  

Console.Write(t1 == t2);

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

static void Main(string[] args)
{
    object obj = "hello";
    Type t1 = typeof(object); 
    Type t2 = obj.GetType();  

    Console.Write(t1 == t2);
}

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

int i = null;
Console.WriteLine(i);

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

static void Main(string[] args)
{
    int? i = null;
    int j = 10;

    if (i < j)
        Console.WriteLine("i < j");
    else if( i > 10)
        Console.WriteLine("i > j");
    else if( i == 10)
        Console.WriteLine("i == j");
    else
        Console.WriteLine("Could not compare");
}

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

static void Main(string[] args)
{
    int? i = null;
    int j = 10;

    if (Nullable.Compare(i, j) < 0)
        Console.WriteLine("i < j");
    else if (Nullable.Compare(i, j) > 0)
        Console.WriteLine("i > j");
    else
        Console.WriteLine("i = j");
} 

Question 38: Which of the following statements is TRUE?

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

static void Main()
{
    object[] arr = new String[10];
    arr[0] = 100;
    
    Console.Write(arr[0]);
}

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

static void Main()
{
    var emp = new
    {
        Id = 1,
        Name = "Steve",
        isActive = true
    };

    emp.Name = "James";
    Console.Write(emp.Name);
}