How should you complete the relevant 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.
How should you complete the relevant code? (To answer, drag the appropriate code segments to the correct locations 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 “How should you complete the relevant code?

  1. Here is a catch ” is also an element not value of the element”. Using MoveToElement() method reader meves back to the element, but doesn’t have value. You must use ReadToFollowing(“value”) in order to read ‘s value.

  2. 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(
    ” ” + “”
    + ” ”
    + ” 0.0375″ + ” ”
    + ” ”
    + ” 0.0475″ + ” ”
    + “”)))
    {
    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.