Visual Programming MCQs with Answers
Practice important Visual Programming MCQs with answers and explanations.
Chapter: 9
Q241:
Which of the following is a generic collection in C#?
A. ArrayList
B. List<int>
C. Hashtable
D. Queue
Correct Answer:
B
Chapter: 9
Q242:
How do you add an item to a List<int> in C#?
A. list.Add(1);
B. list[0] = 1;
C. list.Insert(0, 1);
D. list.Append(1);
Correct Answer:
A
Chapter: 9
Q243:
What method is used to retrieve the number of elements in a List<int>?
A. Count()
B. Length()
C. Size()
D. Count
Correct Answer:
D
Chapter: 9
Q244:
Which statement is true about operator overloading?
A. Operators can only be overloaded for classes
B. Overloaded operators must be static
C. Operators can be overloaded for all types
D. Overloading changes operator precedence
Correct Answer:
B
Chapter: 9
Q245:
What does the [STAThread] attribute signify?
A. Single-threaded apartment model
B. Multi-threaded apartment model
C. Single-threaded application
D. Static threading attribute
Correct Answer:
A
Chapter: 9
Q246:
Which attribute is used to mark a method as compliant with the CLS?
A. STAThread
B. Obsolete
C. CLSCompliant
D. Serializable
Correct Answer:
C
Chapter: 9
Q247:
What is the purpose of the Dictionary<int, Customer> collection?
A. To store key-value pairs
B. To store a list of customers
C. To sort customers by ID
D. To map customer IDs to their names
Correct Answer:
A
Chapter: 9
Q248:
How do you retrieve a customer's name from a Dictionary<int, Customer>?
A. customer.Name
B. dictionary.GetValue(customer.ID)
C. dictionary[customer.ID].Name
D. dictionary.Values.Name
Correct Answer:
C
Chapter: 10
Q249:
What is an anonymous method used for in C#?
A. Declaring a new class
B. Handling events and delegates
C. Creating a new type of loop
D. Defining a static method
Correct Answer:
B
Chapter: 10
Q250:
How do you attach an anonymous method to an event in C#?
A. Using the new keyword
B. Using the delegate keyword
C. Declaring a named method
D. Using a lambda expression
Correct Answer:
B
Chapter: 10
Q251:
What is the correct syntax to declare an anonymous method that takes no parameters?
A. delegate { /* code */ };
B. delegate() { /* code */ };
C. delegate(object sender) { /* code */ };
D. delegate void() { /* code */ };
Correct Answer:
A
Chapter: 10
Q252:
What does the ?? operator do with nullable types in C#?
A. Converts a nullable type to a non-nullable type
B. Provides a default value if the nullable type is null
C. Forces a nullable type to be non-nullable
D. Checks if a nullable type is equal to zero
Correct Answer:
B
Chapter: 10
Q253:
What does the finally block in a try-catch-finally statement ensure in C#?
A. It allows the program to continue without interruption
B. It executes code regardless of whether an exception is thrown
C. It handles exceptions that are not caught
D. It stops the program from executing further
Correct Answer:
B
Chapter: 10
Q254:
Which class in C# allows you to read XML data one element at a time?
A. XmlDocument
B. XmlReader
C. XmlWriter
D. XmlSerializer
Correct Answer:
B
Chapter: 10
Q255:
How does XmlReader differ from XmlDocument in handling XML data?
A. XmlReader loads the entire document into memory
B. XmlDocument is faster and uses less memory
C. XmlDocument reads one element at a time
D. XmlReader is more memory efficient and faster
Correct Answer:
D
Chapter: 10
Q256:
What is the default underlying type of an enum in C#?
A. byte
B. short
C. int
D. long
Correct Answer:
C
Chapter: 10
Q257:
How do you create a nullable integer in C#?
A. int? myValue = null;
B. int myValue = null;
C. Nullable<int> myValue = null;
D. Nullable myValue = null;
Correct Answer:
A
Chapter: 10
Q258:
What method would you use to get a list of all the element names in an XML document using XmlDocument?
A. GetElementsByTagName
B. SelectNodes
C. GetNodeNames
D. SelectSingleNode
Correct Answer:
B
Chapter: 10
Q259:
Which XML class in C# is used for creating or writing XML data?
A. XmlReader
B. XmlWriter
C. XmlDocument
D. XmlSerializer
Correct Answer:
B
Chapter: 10
Q260:
How do you write an XML document to a file using XmlWriter in C#?
A. XmlWriter.WriteFile("file.xml");
B. XmlWriter.Save("file.xml");
C. XmlWriter.Create("file.xml");
D. XmlWriter.Open("file.xml");
Correct Answer:
C