You need to serialize an object of type List in a binary format. The object is named data. Which code segment should you use?

You need to serialize an object of type List<int> in a binary format. The object is named data.
Which code segment should you use?


A. BinaryFormatter^ formatter = gcnew BinaryFormatter();MemoryStream^ stream = gcnew 
    MemoryStream();formatter->Serialize(stream, data);
B. BinaryFromatter^ formatter = gcnew BinaryFormatter();MemoryStream^ stream = gcnew 
    MemoryStream(); for (int i = 0; i < data->Count; i++) {
    formatter->Serialize(stream, data[i]);}
C. BinaryFormatter^ formatter = gcnew BinaryFormatter();array<Byte>^ buffer = gcnew 
    array<Byte>(data->Count);MemoryStream^ stream = gcnew MemoryStream(buffer, true);     
    formatter->Serialize(stream, data);
D. BinaryFormatter^ formatter = gcnew BinaryFormatter();MemoryStream^ stream = gcnew 
    MemoryStream();Capture c(formatter, stream);data->ForEach(gcnew Action<int>(%c, 
    &Capture::Action));

Answer: A 






No comments:

Post a Comment