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 = 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, data); }
    );

 

Answer: A
 

No comments:

Post a Comment