You are troubleshooting an application that uses a class named FullName. The class is decorated with the
DataContractAttribute attribute. The application includes the following code. (Line numbers are included for
reference only.)
You need to ensure that the entire FullName object is serialized to the memory stream object.
Which code segment should you insert at line 09?
A.
binary.WriteEndDocument();
B.
binary.WriteEndDocumentAsync();
C.
binary.WriteEndElementAsync();
D.
binary.Flush();
Explanation:
* DataContractSerializer.WriteEndObject Method (XmlDictionaryWriter)
Writes the closing XML element using an XmlDictionaryWriter.
* Note on line 07: DataContractSerializer.WriteObject Method
Writes all the object data (starting XML element, content, and closing element) to an XML document or stream.
XmlDictionaryWriter
D
D
Correct answer is D binary.Flush()
verified from MSDN
Ajay
August 25, 2015 at 2:19 pm
MemoryStream stream2 = new MemoryStream();
XmlDictionaryWriter binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream2);
serializer.WriteObject(binaryDictionaryWriter, record1);
binaryDictionaryWriter.Flush();
https://msdn.microsoft.com/en-us/library/ms752244(v=vs.110).aspx
Yes D is answer : Tried a Program
var ms = new MemoryStream();
var binary = XmlDictionaryWriter.CreateBinaryWriter(ms);
var ser = new DataContractSerializer(typeof(FullName));
var name = new FullName
{
FirstName = “Sachin”,
LastName = “Tendulkar”
};
ser.WriteObject(binary, name);
Console.WriteLine(“Before Data Written” + ms.Length);
binary.Flush();
//binary.WriteEndDocument();
Console.WriteLine(“After Data Written”+ ms.Length);
Console.ReadLine();
D ans