Destination class: Parse/TryParse methods Add 2 methods to the Destination class. These methods will receive a string co
Posted: Fri Jul 01, 2022 5:46 am
Destination class: Parse/TryParse methods
Add 2 methods to the Destination class. These methods willreceive a string consisting of comma separated values. The stringrepresents a single instance of a Destination. The givenDestination class code is valid and does not need to bealtered.
The Parse method will break the string apart and return aninstance of Destination.
The TryParse method will receive a string representing aninstance of Destination. The method will return a boolean valueindicating a successful creation of a Destination instance. Themethod out parameter will return the Destination instance of theparsed string. DO NOT include atry/catch in the method.
CODE
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;
namespace Assessment{ public class Destination { public string Location { get; privateset; } public DateTime VisitDate { get;private set; }
public Destination (stringlocation, DateTime visitDate) { if(string.IsNullOrWhiteSpace(location)) { throw newArgumentNullException("Location is required"); } Location=location; VisitDate=visitDate; }
public override stringToString() { return$"{Location},{VisitDate}"; }
//TODO 1: Create Parse() andTryParse() methods }}
Add 2 methods to the Destination class. These methods willreceive a string consisting of comma separated values. The stringrepresents a single instance of a Destination. The givenDestination class code is valid and does not need to bealtered.
The Parse method will break the string apart and return aninstance of Destination.
The TryParse method will receive a string representing aninstance of Destination. The method will return a boolean valueindicating a successful creation of a Destination instance. Themethod out parameter will return the Destination instance of theparsed string. DO NOT include atry/catch in the method.
CODE
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;
namespace Assessment{ public class Destination { public string Location { get; privateset; } public DateTime VisitDate { get;private set; }
public Destination (stringlocation, DateTime visitDate) { if(string.IsNullOrWhiteSpace(location)) { throw newArgumentNullException("Location is required"); } Location=location; VisitDate=visitDate; }
public override stringToString() { return$"{Location},{VisitDate}"; }
//TODO 1: Create Parse() andTryParse() methods }}