Read string value from console and add to StringBuilder - CSharp Language Basics

CSharp examples for Language Basics:Console

Description

Read string value from console and add to StringBuilder

Demo Code

using System;//from w  w  w  . j a  v a 2 s .  c o  m
using System.Text;
class Program
{
   static void Main(string[] args)
   {
      StringBuilder builder = new StringBuilder();
      while (true)
      {
         Console.WriteLine("Type a word: ");
         string input = Console.ReadLine();
         if (input == "")
         {
            break;
         }
         else
         {
            builder.Append(input + " ");
         }
      }
      Console.WriteLine("Result: {0}", builder.ToString());
   }
}

Result


Related Tutorials