Programming in C# — Question 127

You need to write a method that retrieves data from a Microsoft Access 2013 database. The method must meet the following requirements:
✑ Be read-only.
✑ Be able to use the data before the entire data set is retrieved.
✑ Minimize the amount of system overhead and the amount of memory usage.
Which type of object should you use in the method?

Answer options

Correct answer: D

Explanation

The correct choice is D, DbDataReader, because it provides a forward-only, read-only stream of data, which allows for efficient memory usage and immediate access to data without loading the entire dataset. Options A and C, while capable of retrieving data, are designed for scenarios that may require more memory and processing overhead since they typically load data into memory. Option B, unTyped DataSet, is not suitable as it stores data in memory and does not meet the read-only requirement.