-2

I have to write a program in which after typing three names it should answer me with "Hello !", but there is problems with the Console.Writeline function...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace homework1
{
    class Program
    { 
        static int Main()
        {
            string firstName = Console.ReadLine();
            string surName = Console.ReadLine();
            string lastName = Console.ReadLine();

            Console.WriteLine("Hello, " + firstName[] + "!");

            //Console.WriteLine("Your full name is " + fullName + ".");
        }
    }
}  
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208

2 Answers2

1

It should be

using System;
using System.Text;

namespace homework1
{
    class Program
    { 
        static int Main()
        {
            string firstName = Console.ReadLine();
            string surName = Console.ReadLine();
            string lastName = Console.ReadLine();

            Console.WriteLine("Hello, " + firstName + "!");

            Console.WriteLine("Your full name is " + 
                String.Format("{0} {1} {2}", firstName, surName , lastName ) + ".");

            return 0;
        }
    }
}

Here is a working example.

enter image description here

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
0

Try this...

Console.WriteLine("Hello, " + firstName + "!");
jiten
  • 5,128
  • 4
  • 44
  • 73