Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Challenge 1 string exercise: SwapInfo Create a method in C# that prompts the use

ID: 3711546 • Letter: C

Question

Challenge 1 string exercise: SwapInfo Create a method in C# that prompts the user for their first and last name. Validate and save the user responses, manipulate this data, and then present it back to the user. Your code should do the following:

1. Display to the user the information they have entered

2. Reverse the order of the information entered

3. Display to the user the new order User Input: Prompt the user at least twice, and request their first and last name Validate the data entered by the user If validation doesn’t pass, request information again Console Output: Output to the console information each time it is entered. For example, “Your first name is… “ + firstName; Use a method to swap the order of data entered. For example, variable A is now set to the value of Variable B and vice versa. Display the data entered in reverse order

Explanation / Answer

using System;

class Program
{
static void Main()
{
SwapInfo();
}
static void SwapInfo() {
Console.WriteLine("Enter the first name: ");
string firstName = Console.ReadLine();
Console.WriteLine("Enter the last name: ");
string lastName = Console.ReadLine();
Console.WriteLine("Before swapping, first name: "+firstName+" last name: "+lastName);
  
string t = firstName;
firstName = lastName;
lastName = t;
Console.WriteLine("After swapping, first name: "+firstName+" last name: "+lastName);
}
}

Output:

Enter the first name: Suresh
Enter the last name: Murapaka
Before swapping, first name: Suresh last name: Murapaka
After swapping, first name: Murapaka last name: Suresh