Collections_quiz.md - brainchildservices/curriculum GitHub Wiki

  1. Which among the following is not the ordered collection class?

a) BitArray

b) Queue

c) Stack

d) None of the mentioned

Answer: a

  1. Which among the following is not an interface declared in System. Collection namespace?

a) IDictionaryComparer

b) IEnumerable

c) IEnumerator

d) Icomparer

Answer: a

  1. Which among the following is the correct way to find out the number of elements currently present in an ArrayListCollection called arr?

a) arr.Capacity

b) arr.Count

c) arr.MaxIndex

d) arr.UpperBound

Answer: b

  1. Which statement is correct in the following C#.NET code snippet?

# Stack st = new Stack();

# st.Push("Csharp");

# st.Push(7.3);

# st.Push(8);

# st.Push('b');

st.Push(true);

a) Unsimilar elements like “Csharp”, 7.3, 8 cannot be stored in the same stack collection

b) Boolean values can never be stored in Stack collection

c) Perfectly workable code

d) All of the mentioned

Answer: c

  1. Which is the correct statement about an ArrayList collection that implements the IEnumerable interface?

a) To access members of ArrayList from the inner class, it is necessary to pass ArrayList class reference to it

b) The inner class of ArrayList can access ArrayList class members

c) The ArrayList class consist of inner class that implements the IEnumerator interface

d) All of the mentioned

Answer: d

  1. Which statements among the following are correct about the Collection Classes available in Framework Class Library? a) Elements of a collection cannot be transmitted over a network

b) Elements stored in a collection can be modified only if all the elements are of similar types

c) Elements stored in a Collection can be retrieved but cannot be modified

d) Collection classes make use of efficient algorithms to manage the collection, hence improving the performance of the program

Answer: d

  1. Among the given collections which one is I/O index based?

a) ArrayList

b) List

c) Stack

d) Queue

Answer: a

  1. Which among the given statements are correct about the Stack collection?

a) It can be used for evaluation of expressions

b) It is used to maintain a FIFO list

c) Top most element of the Stack collection can be accessed using the Peek()

d) All of the mentioned

Answer: d

  1. A HashTable t maintains a collection of names of states and capital city of each state. Which among the following finds out whether “New delhi” state is present in the collection or not?

a)t.HasValue("New delhi");

b)t.ContainsKey("New delhi");

c)t.HasKey("New delhi");

d)t.ContainsValue("New delhi");

Answer: b

  1. In which of the following collections is the I/O based on a key?

a) BitArray

b) SortedList

c) Queue

d) Stack

Answer: b

  1. The wrong statements about a HashTable collection are?

a) It is a keyed collection

b) It is a ordered collection

c) It’s not an indexed collection

d) It implements a IDictionaryEnumerator interface in its inner class

Answer: b

  1. How many enumerators will exist if four threads are simultaneously working on an ArrayList object?

A.1

B.3

C.2

D.4

E.Depends upon the Project Setting made in Visual Studio.NET.

Answer: Option D

  1. In which of the following collections is the Input/Output index-based?

    1. Stack

    2. Queue

    3. BitArray

    4. ArrayList

    5. HashTable

A. 1 and 2 only

B. 3 and 4 only

C. 5 only

D. 1, 2 and 5 only

E. All of the above

Answer: Option B

  1. In which of the following collections is the Input/Output based on a key?

1.Map

  1. Stack

  2. BitArray

  3. HashTable

  4. SortedList

A.1 and 2 only

B.2 and 3 only

C.1, 2 and 3 only

D.4 and 5 only

E.All of the above

Answer: Option D

  1. In a HashTable Key cannot be null, but Value can be.

A.True

B.False

Answer: Option A

  1. Which of the following is NOT an interface declared in System.Collections namespace?

A. IComparer

B. IEnumerable

C. IEnumerator

D. IDictionaryComparer

E. IDictionaryEnumerator

Answer: Option D

  1. 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?

A. 4

B. 8

C. 16

D. 32

Answer: Option B

  1. Which of the following is an ordered collection class?

  2. Map

  3. Stack

  4. Queue

  5. BitArray

  6. HashTable

A. 1 only

B. 2 and 3 only

C. 4 and 5 only

D. All of the above

E. None of the above

Answer: Option B

  1. Which of the following is the correct way to find out the number of elements currently present in an ArrayList Collection called arr?

A. arr.Count

B. arr.GrowSize

C. arr.MaxIndex

D. arr.Capacity

E. arr.UpperBound

Answer: Option A

  1. Which of the following statements are correct about the Collection Classes available in Framework Class Library?

A. Elements of a collection cannot be transmitted over a network.

B. Elements stored in a collection can be retrieved but cannot be modified.

C. It is not easy to adopt the existing Collection classes for newtype of objects.

D. Elements stored in a collection can be modified only if allelements are of similar types.

E. They use efficient algorithms to manage the collection, thereby improving the performance of the program.

Answer: Option E

  1. For using ArrayList we need to add the -------------- namespace

    Ans: System.Collections

  2. what are the Two ways to create an ArrayList:

    Ans :- 1. Without specifying the capacity of the ArrayList

          2. By specifying the capacity of the ArrayList
    
  3. How to count the number of elements in an ArrayList?

Ans:-The number of elements in an array can be counted using the ArrayList.Count property.

  1. A Hashtable implements ---------- interface.

    Ans: IDictionary

  2. The Hashtable is a ------------- collection that stores key-value pairs.

    Ans: non-generic

  3. Items can be added to the Hashtable using the Add Method. The Add method has two parameters,------------.

Ans:  a key and a value
  1. The Hashtable class provides 2 methods to remove an item or items from it. These methods are:

    1. Remove
    2. Clear
  2. Which one of the following classes are present System.Collections.Generic namespace?

    1. Stack

    2. Tree

    3. SortedDictionary

    4. SortedArray

A. 1 and 2 only

B. 2 and 4 only

C. 1 and 3 only

D. All of the above

E. None of the above

Answer: Option C

  1. Which of the following statements are valid about generics in .NET Framework?

  2. Generics is a language feature.

  3. We can create a generic class, however, we cannot create a generic interface in C#.NET.

  4. Generics delegates are not allowed in C#.NET.

  5. Generics are useful in collection classes in .NET framework.

  6. None of the above

A. 1 and 2 Only

B. 1, 2 and 3 Only

C. 1 and 4 Only

D. All of the above

E. None of the above

Answer: Option C

  1. Which of the following statements is valid about generic procedures in C#.NET?

A. All procedures in a Generic class are generic.

B. Only those procedures labeled as Generic are generic.

C. Generic procedures can take at the most one generic parameter.

D. Generic procedures must take at least one type parameter.

E. None of the above.

Answer: Option D

  1. Which of the following statements is valid about advantages of generics?
    

A. Generics shift the burden of type safety to the programmer rather than compiler.

B. Generics require use of explicit type casting.

C. Generics provide type safety without the overhead of multiple implementations.

D. Generics eliminate the possibility of run-time errors.

E. None of the above.

Answer: Option C

  1. The Dictionary<TKey, TValue> is a ------ collection that stores key-value pairs in no particular order.

    Ans:generic

  2. The List is a -------- collection

    Ans: generic

  3. The --------- method is used to add a collection to a List.

    Ans: AddRange

  4. The ---------- of List class inserts an object at a given position.

    Ans: Insert method

  5. The ---------- removes the first occurrence of the given item in the List.

    Ans: Remove method

  6. IEnumerable in C# is an -----------that is a parent for all the collection class.

    Ans: interface

  7. The enumerator is an -----------that can return each item in a collection, one by one,in order, as they’re requested.

    Ans: object

  8. IEnumerable interface is a --------- interface that allows looping over generic or non-generic lists.

    Ans: generic

  9. IEnumerable interface Returns an --------------- that iterates through the collection.

    Ans: enumerator

  10. IEnumerable has just one method called ------------.

Ans: GetEnumerator

  1. IEnumerator has two methods, what are they?

    Ans: (MoveNext and Reset) and a property Current

  2. SortedList class is a collection of -------- which are sorted according to keys.

    key-value pairs

  3. A SortedList does not allow ------------ keys.

Ans: duplicate

  1. The capacity of a SortedList object is the --------- the SortedList can hold.

    Ans: number of elements

  2. Stack represents a -------------collection of object.

    Ans: last-in, first out

  3. Stack accepts null as a valid value and allows ---------- elements.

Ans: duplicate

  1. Queue represents a ------------- collection of object.

    Ans: first-in, first out

  2. Enqueue adds an element to the ------ of the Queue.

Ans: end

  1. Dequeue removes the oldest element from the ------ of the Queue.

Ans: start

  1. The CompareTo method of the IComparable interface returns an ------ value that shows how two elements are related.

    Ans: int

  2. IComparer interface has method --------------

    Ans: Compare