PrepAway - Latest Free Exam Questions & Answers

Which code segment should you insert at line 20?

You are developing an application. The application converts a Location object to a string by using a method
named WriteObject. The WriteObject() method accepts two parameters, a Location object and an
XmlObjectSerializer object. The application includes the following code. (Line numbers are included for
reference only.)
01 public enum Compass
02 {03 North,
04 South,
05 East,
06 West
07 }
08 [DataContract]
09 public class Location
10 {
11 [DataMember]
12 public string Label { get; set; }
13 [DataMember]
14 public Compass Direction { get; set; }
15 }
16 void DoWork()
17 {
18 var location = new Location { Label = “Test”, Direction = Compass.West};
19 Console.Writeline(WriteObject(location,
20
21 ));
22 }
You need to serialize the Location object as a JSON object. Which code segment should you insert at line
20?

PrepAway - Latest Free Exam Questions & Answers

A.
new DataContractSerializer(typeof(Location))

B.
new XmlSerializer(typeof(Location))

C.
new NetDataContractSenalizer()

D.
new DataContractJsonSerializer(typeof(Location))

Explanation:
DataContractJsonSerializer – Serializes objects to the JavaScript Object Notation (JSON) and
deserializes JSON data to objects. This class cannot be inherited. http://msdn.microsoft.com/en-us/library/
system.runtime.serialization.json.datacontractjsonserializer.aspx

One Comment on “Which code segment should you insert at line 20?


Leave a Reply