You have recently completely creating a new application for Domain.com.
This new application has to load an instance of the Inventory class from a large file named Inventory.dat.
You need to ensure that the application executes the loading process in as little time as possible.
What should you do?
A.
Use the following code:
FileStream readStream = new FileStream (“Inventory.dat”, FileMode.Open);
BinaryFormatter readFormatter = new BinaryFormatter ();
Inventory currentInventory = (Inventory) readFormatter.FastDeserialize(readStream);
B.
Use the following code:
FileStream readStream = new FileStream (“Inventory.dat”, FileMode.Open);
BinaryFormatter readFormatter = new BinaryFormatter ();
Inventory currentInventory = (Inventory)readFormatter.Deserialize (readStream);
C.
Use the following code:
FileStream readStream = new FileStream (“Inventory.dat”, FileMode.Open);
BinaryFormatter readFormatter = new BinaryFormatter ();
Inventory currentInventory = (Inventory)readFormatter.UnsafeDeserialize(readStream);
D.
Use the following code:
FileStream readStream = new FileStream (“Inventory.dat”, FileMode.Open);
BinaryFormatter readFormatter = new BinaryFormatter ();
Inventory currentInventory = (Inventory)readFormatter.SafeDeserialize(readStream);
Explanation:
This code instantiates a file stream, instantiates a BinaryFormatter object, and deserializes an Inventory object to the Inventory.dat file.
The UnsafeDeserialize and Deserialize methods perform the same operation, but the UnsafeDeserialize method uses
unmanaged code and requires more permission.
Because the UnsafeDeserialize method uses unmanaged code, your code should be granted full trust to execute properly.
The UnsafeDeserialize method of the BinaryFormatter class takes two arguments, the stream of the object to be deserialized
and the HeaderHandler object to deal with any binary headers. The UnsafeDeserialize method returns a generic object that must be cast or converted to the Inventory data type.
Incorrect Answers:
A, D: You should not use the code that invokes the FastDeserialize and SafeDeserialize methods because no such methods exist for the BinaryFormatter class.
B: You should not use the code that invokes the Deserialize method because the UnsafeDeserialize method yields better performance.
None of the above. Signature is wrong for UnsafeDeserialize.
I agree with the answer. C