You need to serialize an object of type List in a binary format.
The object is named data.
Which code segment should you use?
A.
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, data);
B.
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
for (int i= 0;i <data.Count; i++) {
formatter.Serialize(stream, data[i]);
}
C.
BinaryFormatter formatter = new BinaryFormatter();
byte[] buffer = new byte[data.Count];
MemoryStream stream = new MemoryStream(buffer, true);
formatter.Serialize(stream, data);
D.
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
data.ForEach(delegate(int num){
formatter.Serialize(stream, num);
} );
Explanation:
create a BinaryFormatter and a MemoryStream and simply use the formatter to serialize the data to the stream.
B Collections support serialization, hence it is not required to try to serialize each item independently.
C The MemoryStream is created to be non resizeable and it is not the correct size.
A