PrepAway - Latest Free Exam Questions & Answers

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

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:

4 Comments on “How should you complete the relevant code?

    1. Béni says:

      sv1slim, it depends; I created a file and used a file reader to access it:

      var q199Path = @”D:\temp\Q199.xml”;

      var rateCollection = new List();

      using (var q199FileStream = File.OpenRead(q199Path))
      using (var xmlReader = XmlReader.Create(q199FileStream))
      {
      var usCulture = new CultureInfo(“en-us”);

      while (xmlReader.ReadToFollowing(“rate”))
      {
      var rate = new Rate();

      xmlReader.MoveToFirstAttribute();
      rate.Category = xmlReader.Value;

      xmlReader.MoveToNextAttribute();
      if (DateTime.TryParse(xmlReader.Value, out DateTime rateDate))
      {
      rate.Date = rateDate;
      }

      xmlReader.ReadToFollowing(“value”);
      if (decimal.TryParse(xmlReader.ReadElementContentAsString(), NumberStyles.Number, usCulture, out decimal rateValue))
      {
      rate.Value = rateValue;
      }

      rateCollection.Add(rate);
      }
      }




      1



      0

Leave a Reply