Which code segments should you include in Target 1, Target 2, Target 3 and Target 4 to complete the code?

DRAG DROP
You are developing a C# application. The application includes a class named Rate. The following code segment implements the Rate class:

You define a collection of rates named rateCollection by using the following code segment:
Collection<Rate> rateCollection = new Collection<Rate>() ;
The application receives an XML file that contains rate information in the following format:

You need to parse the XML file and populate the rateCollection collection with Rate objects.
You have the following code:

Which code segments should you include in Target 1, Target 2, Target 3 and Target 4 to complete the code? (To answer, drag the appropriate code segments to the correct targets in the answer area. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Select and Place:

microsoft-exams

6 thoughts on “Which code segments should you include in Target 1, Target 2, Target 3 and Target 4 to complete the code?

  1. last option reader.MoveToElement() is incorrect.
    Correct answer is
    reader.ReadToFollowing(“value”);

    Code:
    Collection ratecollection = new Collection();
    string rateXML = @”0.03750.0475″;

    using (XmlReader reader = XmlReader.Create(new StringReader(rateXML)))
    {
    while (reader.ReadToFollowing(“rate”))
    {
    Rate rate = new Rate();
    reader.MoveToFirstAttribute();
    rate.Category = reader.Value;
    reader.MoveToNextAttribute();
    DateTime ratedate;
    if (DateTime.TryParse(reader.Value,out ratedate))
    {
    rate.Date = ratedate;
    }
    reader.ReadToFollowing(“value”);
    //reader.MoveToElement(); ReadElementContentAs() methods cannot be called on an element that has child elements. Line 1, position 94.
    decimal value;
    if(Decimal.TryParse(reader.ReadElementContentAsString(),out value))
    {
    rate.Value = value;
    }
    ratecollection.Add(rate);
    }
    foreach(Rate rate in ratecollection)
    {
    Console.WriteLine(“Date {0} Value {1}”, rate.Date, rate.Value);
    Console.WriteLine(“Category {0} Date {1} Value {2}”, rate.Category, rate.Date, rate.Value);
    }
    /*
    Date 3/22/2012 12:00:00 AM Value 0.0375
    Date 3/22/2012 12:00:00 AM Value 0.0475
    Category buyout Date 3/22/2012 12:00:00 AM Value 0.0375
    Category fixed Date 3/23/2012 12:00:00 AM Value 0.0475
    */
    }

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.