csharp Collections Questions & Answers

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

using System;
using System.Collections.Generic;
		
public class Program
{
	public static void Main()
	{
		string[] strArr = {"Hello","World"};
        		
        IList<string> strList = strArr;
		IList<object> objList = strArr;

		Console.Write(strList[0] + objList[1]);
	}
}

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

public class Program
{
	public static void Main()
	{
		int i = 3;
		int[] arr = new int[i] {10, 20, 30};

		Console.Write(arr[0]);
	}
}

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

public static void Main(string[] args)
{
	int[] arr = {1, 2, 3};
	display(arr);
	display(4,5,6);
}

static void display(params int[] arr){
	
	foreach(var i in arr)
		Console.Write(i);
}
ADVERTISEMENT

Question 9: Which of the following collection type will you use to hold values of different data types?

Question 10: Which of the following is LIFO (Last In First Out) collection?