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.)

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:
The DataContractJsonSerializer class serializes objects to the JavaScript Object Notation (JSON) and
deserializes JSON data to objects.
Use the DataContractJsonSerializer class to serialize instances of a type into a JSON document and to
deserialize a JSON document into an instance of a type.

3 Comments on “Which code segment should you insert at line 20?

  1. Swapnil says:

    D :Confirmed
    public void Dowork()
    {
    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Location));
    var location = new Location { Label = “Test”, Direction = Compass.West };
    System.IO.FileStream fs = new System.IO.FileStream(“D:\\hello.txt”, System.IO.FileMode.OpenOrCreate);

    ser.WriteObject(fs, location);
    Console.WriteLine(“Serialized”);
    }
    static void Main(string[] args)
    {
    Program p = new Program();
    p.Dowork();
    Console.ReadLine();
    }




    5



    0

Leave a Reply