Question:
This is for a beginner class in c#
I am having a hard time converting this code i made into amethod and figuring out a way to call it in main.
Any help will be greatly appreciated!!!
Write(“state (2 letters):t”); stateAbbreviation Read Line ) //Extra credit: use binary search method fieldvalidationsuccess false; while !fieldvalidationSuccess) int sub e; while (sub < states. Length && !fieldvalidationsuccess) stateAbbreviation. ToUpper ()) if (states[sub].ToUpper() fieldvalidationSuccess = true; } else sub++ if (!fieldvalidationsuccess) WriteLine (“n***ERROR. We do not ship to se}.”, stateAbbreviation); //Extra credit: display a string with a comma-separated list of valid states WriteLine($”We only ship to these states: string.Join(“, “, states)}”); write(“Please give it another shot: “); stateAbbreviation = ReadLine () ; string GetValidState ( string prompt, string[] sortedStateArray) Reads and validates string input from the user using the supplied prompt. Validation: The returned string must precisely 2 characters long. The input value must match a value in the supplied state array Notes: Initialize the state array in Main() Build a validation loop to ensure that the user enters a valid state abbreviation Use a loop to search the array for a valid state. Do not use Array.BinarySearch Call GetValidString to get the string from the user. Use 2 for both the min and max parameters. Show transcribed image text Write(“state (2 letters):t”); stateAbbreviation Read Line ) //Extra credit: use binary search method fieldvalidationsuccess false; while !fieldvalidationSuccess) int sub e; while (sub
Expert Answer
Answer to Question: This is for a beginner class in c# I am having a hard time converting this code i made into a method and figu…