Knowledge Check3
Knowledge Check3
Note: When grading, each question is worth 3.12 points (%) for a total of 100 (%).
1) What is the .NET collection class that allows an element to be accessed using a
unique key?
a. ArrayList
b. HashTable
c. StringCollection
d. None of the above
A is incorrect. ArrayList does not use unique key to access its elements.
B is the correct answer. HashTable is the collection class in which the elements can be
accessed using a unique key.
C is incorrect. StringCollection does not use a unique key. One way of accessing elements in
a StringCollection is by the use of the IEnumerator.
a. System.Collections
b. System.Globalization
c. System.Object
d. System.IO
a. System.String
b. Char Array
c. Struct
d. StringBuilder
e. All of the above
StringBuilder is best suited for this purpose as it does not create a new string every time the
value of the string is modified. System.String creates a new string whenever the value is
modified.
a. System.Globalization
b. System.Localization
c. A custom namespace with custom functions written to handle localization.
d. None as it is available by default.
5) Which of the following should be inherited from when writing Custom Collections?
a. ICollection
b. CollectionBase
c. Both a and b.
d. Write your own base class and inherit from it.
All custom collection classes should inherit from CollectionBase. ICollection is an interface
which is used by most of the collection classes.
a. Caller’s permission
b. Declarer’s permission
c. The most strict permission available
d. The least strict permission available
e. It does not require any permission to run.
a. XML serialization serializes only the public fields and property values of an
object.
b. XML serialization results in strongly-typed classes with public properties and
fields that are converted to a serial format for storage or transport.
c. XML serialization converts all methods, private fields, or read-only
properties (irrespective of their access modifier).
d. Both a and b.
e. None of the above.
A) and B) are both correct. XML Serialization can be used to serialize only the public fields
and properties. To serialize all an object's fields and properties, both public and private, use
the BinaryFormatter instead of XML serialization. Also, XML Serialization does not include any
type information.
8) The class that encapsulates the event information should be derived from:
a. System.EventArgs
b. System.EventHandler
c. System.Delegate
d. System.ComponentModel.EventDescriptor
e. None of the above
The class that encapsulates the event information should be derived from EventArgs.
System.EventHandler represents the method that will handle the event that has no event data.
The Delegate class is the base class for delegate types. ComponentModel.EventDescriptor
class provides information about an event.
10) Which of the following classes are used to read and write encoded strings and
primitive datatypes from and to streams?
BinaryReader and BinaryWriter are used to read and write encoded strings and primitive
datatypes from and to streams. StreamReader and StreamWriter are used to read and write
characters from and to streams. TextReader and TextWriter are the abstract base classes.
a. They are a method, get accessor, or operator that supports foreach iteration
in a class or struct.
b. They are used in collection classes.
c. Using an iterator allows us to traverse a data structure without having to
implement the IEnumerable interface.
d. All of the above.
e. Both a and c.
A static class does not allow adding of non static members. We cannot create an instance of a
static class. A static class cannot be derived.
Nullable Types are value type variable that can be assigned the value of null. The HasValue
and Value property is used to test for null and to retrieve value of a Nullable type. The
System.Nullable.GetValueorDefault property is used to return the assigned value or the
default value for the underlying type.
a. ::global
b. global::
c. global:
d. None of the above
(a) An abstract class cannot be instantiated. (b) A class with at least one abstract method
must be declared as an abstract class. (c) A class that has at least one abstract method,
whether declared or inherited from an abstract class, must be declared abstract. (d) You may
not use the abstract modifier on a static property as this will result in an error.
(a) All interface members implicitly have public access. (b) Correct. The rule for an Interface is
that an object of a class can be casted to the interface which it implements. (c) A class
implementing an interface must implement all the members declared within the interface. (d)
The interface itself does not provide implementations for the members that it defines.
22) Which of the following statements about the overloadability of operators are true?
(Select the best option)
(a) All classes have static constructors. (b) Static constructor doesn’t have parameters and
access modifiers cannot be applied to it. (c) Correct. Static constructor gets executed when
static members of a class are accessed for the first time or when an object of the class is
created. (d) Static variables get instantiated before the static constructor.
(a) Classes under System.Threading help implementation of threading in .NET. (b) Correct.
ThreadStart delegate is used for long running tasks while ThreadPool is used for short running
tasks. (c) Multiple threads within a process can share common data amongst them. (d)
Multiple processes cannot share common resources.
a. Delegates are type-safe function pointers where any method can be called
through the delegate.
b. Async delegate calls can be made using the BeginInvoke() and
EndInvoke() methods of a delegate.
c. Multiple methods attached to a delegate get executed in an asynchronous
manner when the delegate is called.
d. An event-like pattern can be implemented using events only.
(a) To call a method through a delegate, the signature of the delegate and the method must
match. (b) Correct. Async delegate calls can be made using the BeginInvoke() and
EndInvoke() methods of a delegate. (c) Multiple methods attached to a delegate gets
executed synchronously in the order in which they got attached. (d) Delegates and events
work hand-in-hand to produce event-like pattern.
Threads can be implemented by directly or indirectly using the ThreadPool class, by using the
ThreadStart delegate, and by the BeginInvoke() method of delegate. (d) By the BeginRead()
method of Stream.
namespace TestThreading
{
class Program
{
static void Main()
{
ThreadStart task1 = new ThreadStart(ProcessTask1);
Thread t1 = new Thread(task1);
t1.Start();
Console.ReadLine();
}
a. Thread t1 in action
Thread t1 in action
Thread t1 in action
b. Error in the program
c. Thread t1 in action
d. None of the above
Statement1: Join() method – This method blocks the calling thread until the thread
terminates.
Statement2: Sleep() method – This method blocks the thread for a specific
amount of time.
Statement1: Lowest priority – The thread with this priority can be scheduled after
threads with any other priority.
Statement2: Highest priority – The thread with this priority can be scheduled
before threads with any other priority.
Statement1: Which gives us the capabilities to assess our own custom methods
to data types without deriving from the base class.
Statement2: Allows you to pass in named values for each of the public properties
that will be used to initialize the object.
31) Each XML document has exactly one ___________, also known as the document
element.
a. XML declaration
b. root element
c. closing
d. attribute
e. opening
32) __________ are information not part of the data the element holds.
a. XML declarations
b. Root elements
c. Openings
d. Closings
e. Attributes