-2

我必须编写一个程序,在输入三个名字后它应该用“Hello!”回答我,但是 Console.Writeline 函数存在问题......

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 + ".");
        }
    }
}  
4

2 回答 2

1

它应该是

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;
        }
    }
}

这是一个工作示例。

在此处输入图像描述

于 2013-10-11T12:18:07.787 回答
0

尝试这个...

Console.WriteLine("Hello, " + firstName + "!");
于 2013-10-11T12:19:00.777 回答