Reading & Writing to Console

2. Write a C# program to read and write "Hello <first name><last name>" in the console.

using System;
class Program
{
    static void Main()
    {
        Console.WriteLine("Please enter your first name");
        string firstName = Console.ReadLine();

        Console.WriteLine("Please enter your last name");
        string lastName = Console.ReadLine();

        //using concatenation
        Console.WriteLine("Hello " + firstName +" "+ lastName);

        //using placeholder
        Console.WriteLine("Hello {0} {1}", firstName, lastName);
    }
}

Output:


Comments

Popular posts from this blog

Introduction to C#

Common Operators in C#

Built-in types in C#