🧩 C# Programming MCQs and Exam Questions

Practice 151 approved 🧩 C# Programming MCQs and exam questions from the 💻 Programming subject.

151 solved MCQs

Which of the following is the correct way to call subroutine MyFun() of the Sample class given below? class Sample { public void MyFun(int i, Single j) { Console.WriteLine("Welcome to IndiaBIX !"); } }Answer: delegate void del(int i, Single j); del d; Sample s = new Sample(); d = new del(ref s.MyFun); d(10, 1.1f); Which of the following statements are correct about a delegate? 1. Inheritance is a prerequisite for using delegates. 2. Delegates are type-safe. 3. Delegates provide wrappers for function pointers. 4. The declaration of a delegate must match the signature of the method that we intend to call using it. 5. Functions called using delegates are always late-bound.Answer: 2, 3 and 4 only Which of the following statements are correct about delegates? 1. Delegates are not type-safe. 2. Delegate is a user-defined type. 3. Only one method can be bound with one delegate object. 4. Delegates can be used to implement callback notification. 5. Delegates permit execution of a method on a secondary thread in an asynchronous manner.Answer: 2, 4 and 5 only Which of the following statements are correct about delegates?Answer: Delegates cannot be used to call procedures that receive variable number of arguments. Which of the following are the correct ways to declare a delegate for calling the function func() defined in the sample class given below? class Sample { public int func(int i, Single j) { /* Add code here. */ } }Answer: delegate int d(int i, Single j); Suppose on pushing a button an object is to be notified, but it is not known until runtime which object should be notified. Which of the following programming constructs should be used to implement this idea?Answer: Delegate Which of the following statements is incorrect about a delegate?Answer: Delegate is a value type. Suppose a Generic class called SortObjects is to be made capable of sorting objects of any type (Integer, Single, Byte etc.). Which of the following programming constructs should be used to implement the comparision function?Answer: Delegate With which of the following can the ref keyword be used? 1. Static data 2. Instance data 3. Static function/subroutine 4. Instance function/subroutineAnswer: 3, 4 Which of the following statements are correct about an ArrayList collection that implements the IEnumerable interface? 1. The ArrayList class contains an inner class that implements the IEnumerator interface. 2. An ArrayList Collection cannot be accessed simultaneously by different threads. 3. The inner class of ArrayList can access ArrayList class's members. 4. To access members of ArrayList from the inner class, it is necessary to pass ArrayList class's reference to it. 5. Enumerator's of ArrayList Collection can manipulate the array.Answer: 1 and 3 and 4 only How many enumerators will exist if four threads are simultaneously working on an ArrayList object?Answer: 4 In which of the following collections is the Input/Output index-based? 1. Stack 2. Queue 3. BitArray 4. ArrayList 5. HashTableAnswer: 3 and 4 only In which of the following collections is the Input/Output based on a key? 1. Map 2. Stack 3. BitArray 4. HashTable 5. SortedListAnswer: 4 and 5 only In which of the following collections is the Input/Output based on a key? 1. Map 2. Stack 3. BitArray 4. HashTable 5. SortedListAnswer: 4 and 5 only Which of the following statements are correct about the C#.NET code snippet given below? Stack st = new Stack(); st.Push("hello"); st.Push(8.2); st.Push(5); st.Push('b'); st.Push(true);Answer: This is a perfectly workable code. Which of the following statements are correct about the Stack collection? 1. It can be used for evaluation of expressions. 2. All elements in the Stack collection can be accessed using an enumerator. 3. It is used to maintain a FIFO list. 4. All elements stored in a Stack collection must be of similar type. 5. Top-most element of the Stack collection can be accessed using the Peek() method.Answer: 1, 2 and 5 only A HashTable t maintains a collection of names of states and capital city of each state. Which of the following is the correct way to find out whether "Kerala" state is present in this collection or not?Answer: t.ContainsKey("Kerala"); Which of the following is the correct way to access all elements of the Queue collection created using the C#.NET code snippet given below? Queue q = new Queue(); q.Enqueue("Sachin"); q.Enqueue('A'); q.Enqueue(false); q.Enqueue(38); q.Enqueue(5.4);Answer: IEnumerator e; e = q.GetEnumerator(); while (e.MoveNext()) Console.WriteLine(e.Current); Which of the following is NOT an interface declared in System.Collections namespace?Answer: IDictionaryComparer Suppose value of the Capacity property of ArrayList Collection is set to 4. What will be the capacity of the Collection on adding fifth element to it?Answer: 8 Which of the following is an ordered collection class? 1. Map 2. Stack 3. Queue 4. BitArray 5. HashTableAnswer: 2 and 3 only Which of the following is the correct way to find out the number of elements currently present in an ArrayList Collection called arr?Answer: arr.Count Which of the following statements are correct about a HashTable collection? 1. It is a keyed collection. 2. It is a ordered collection. 3. It is an indexed collection. 4. It implements a IDictionaryEnumerator interface in its inner class. 5. The key - value pairs present in a HashTable can be accessed using the Keys and Values properties of the inner class that implements the IDictionaryEnumerator interface.Answer: 1, 4 and 5 only Which of the following is the correct way to access all elements of the Stack collection created using the C#.NET code snippet given below? Stack st = new Stack(); st.Push(11); st.Push(22); st.Push(-53); st.Push(33); st.Push(66);Answer: IEnumerator e; e = st.GetEnumerator(); while (e.MoveNext()) Console.WriteLine(e.Current); Which of the following statements are correct about the Collection Classes available in Framework Class Library?Answer: They use efficient algorithms to manage the collection, thereby improving the performance of the program. Which of the following statements is correct about the C#.NET code snippet given below? interface IMyInterface { void fun1(); int fun2(); } class MyClass: IMyInterface { void fun1() { } int IMyInterface.fun2() { } }Answer: The definition of fun1() in class MyClass should be void IMyInterface.fun1(). Which of the following can be declared in an interface? 1. Properties 2. Methods 3. Enumerations 4. Events 5. StructuresAnswer: 1, 2, 4 A class implements two interfaces each containing three methods. The class contains no instance data. Which of the following correctly indicate the size of the object created from this class?Answer: 24 bytes Which of the following statements is correct about an interface used in C#.NET?Answer: Properties can be declared inside an interface. Which of the following statements is correct about Interfaces used in C#.NET?Answer: Interfaces can be inherited.