2013-10-11 21 views
-2

我必須寫一個程序中,鍵入三個名字後,應該回答我,「你好!」,但與Console.WriteLine命令功能問題...我必須寫一個程序,在輸入三個名字後,它應該回答我「你好<firstName>!」

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

任何理由使用的firstName'[]''而不是firstName'? –

回答

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

這是一個工作示例。

enter image description here

0

嘗試......

Console.WriteLine("Hello, " + firstName + "!"); 
相關問題