CSharp - Write program to Read and Join More than one Text Value

Requirements

You will write a program that accumulates names entered by the user.

You will make two accumulations:

  • one is in the original order, and
  • the second one is in the reverse order.

Demo

using System;
class Program/*from  ww  w . j  a  v  a  2 s .com*/
{
    static void Main(string[] args)
    {
        // Preparation - variables to accumulate intermediate results 
        string r = "";
        string inReversedOrder = "";

        // Input of the first person 
        Console.Write("Enter first person: ");
        string person = Console.ReadLine();

        // Appending the first person to intermediate result 
        r += person + Environment.NewLine;
        inReversedOrder = person + Environment.NewLine + inReversedOrder;

        // Input of the second person 
        Console.Write("Enter second person: ");
        person = Console.ReadLine();

        // Appending the second person to intermediate result 
        r += person + Environment.NewLine;
        inReversedOrder = person + Environment.NewLine + inReversedOrder;

        // Input of the third person 
        Console.Write("Enter third person: ");
        person = Console.ReadLine();

        // Appending the third person to intermediate result 
        r += person + Environment.NewLine;
        inReversedOrder = person + Environment.NewLine + inReversedOrder;

        Console.WriteLine("Entered persons");
        Console.WriteLine(r);

        Console.WriteLine("In reversed order");
        Console.WriteLine(inReversedOrder);

    }
}

Result