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 rateCollection = new Collection() ;
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

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

  1. Sorry, to correct myself. I have tried it out and reader.ReadToFollowing(“value”) is definitely correct. If you want to try yourself, here is the code

    private static void ReadXml()
    {
    var rates = new List();
    using (XmlReader reader = XmlReader.Create(
    new StringReader(
    // insert xml here
    ))
    {
    while (reader.ReadToFollowing(“rate”))
    {
    var rate = new Rate();
    reader.MoveToFirstAttribute();
    rate.Category = reader.Value;
    reader.MoveToNextAttribute();
    rate.Date = DateTime.ParseExact(reader.Value, “yyyy-mm-dd”, CultureInfo.InvariantCulture);
    reader.ReadToFollowing(“value”);
    rate.Value = decimal.Parse(reader.ReadElementContentAsString(), CultureInfo.InvariantCulture);
    rates.Add(rate);
    }
    }

    rates.ForEach(rate => Console.WriteLine($”{rate.Category} {rate.Date:d} {rate.Value}”));
    }

    public class Rate
    {
    public string Category { get; set; }
    public DateTime Date { get; set; }
    public decimal Value { get; set; }
    }

Leave a Reply

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


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