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?

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?

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



Leave a Reply 1

Your email address will not be published. Required fields are marked *