csharp Collections Questions & Answers

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

SortedList sortedList = new SortedList()
                            {
                                {2, true},
                                {1,"one"},
                            };
foreach(DictionaryEntry kvp in sortedList )
    Console.Write(kvp.Value);

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

Stack myStack = new Stack(){
			1,2,3,4,5
		};
		
foreach (var itm in myStack)
	Console.Write(itm);

Question 23: Which interface(s) must be implemented in the custom collection class in order to iterate it with the foreach loop?

ADVERTISEMENT

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

public class Program
{
	public static void Main()
	{
		int[] arr = {1,2,3};
		Display(arr);
		
		ArrayList arList = new ArrayList(){ 4,5,6};
		Display(arList);
		
		IList lst = new List(){ 7,8,9};
		Display(lst);
	}
	
	public static void Display(IEnumerable col){
		foreach (var val in col)
			Console.Write(val); 
	}
}

Question 25: Which of the following collection stores key-value pairs?