Question: Please help with this .class C# Need help validating that the entered state is valid Program the Address class, to validate the states, throw ArgumentException

Please help with this .class C#

Need help validating that the entered state is valid Program the Address class, to validate the states, throw ArgumentException if state entered in the constructor aren't in the list be sure to catch the ArgumentException for a bad state value.

class Address { private string street; private string city; private string state; private string zip;

public string Street { get; set; } public string City { get; set; } public string Zip { get; set; }

public string State { get { return state; } set { string[] states = { "Alabama", "Alaska", "Arizona", " Arkansas", " California", " Colorado", " Connecticut", " Delaware", " Florida", " Georgia", " Hawaii", " Idaho", " Illinois", " Indiana", " Iowa", " Kansas", " Kentucky", " Louisiana", " Maine", " Maryland", " Massachusetts", " Michigan", " Minnesota", " Mississippi", " Missouri", " Montana", " Nebraska", " Nevada", " New", " Hampshire", " New Jersey", " New Mexico", " New York", " North Carolina", " North Dakota", " Ohio", " Oklahoma", " Oregon", " Pennsylvania", " Rhode Island", " South Carolina", " South Dakota", " Tennessee", " Texas", " Utah", " Vermont", " Virginia", " Washington", " West Virginia", " Wisconsin", " Wyoming"}; if (value > states[]) { throw new ArgumentException(nameof(value), value, $"{nameof(states[])} That state doesn't exist"); } } } public Address(string street, string city, string state, string zip) { Street = street; City = city; // State = state; Zip = zip; }

public override string ToString() { string adr = $"{Street}, {City}, {State}, {Zip}"; return adr; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!