A.Speak(“你好{0},你今天过得怎么样”,姓名);

时间:2017-08-03 13:05:32

标签: c#

我需要这段代码的帮助:

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

namespace ConsoleApplication1
{
    class Program
    {



        static void Main(string[] args)
        {
            SpeechSynthesizer A = new SpeechSynthesizer();

            A.SelectVoiceByHints(VoiceGender.Neutral);
            A.Speak("Hello, my name is Ezou. What's yours?");
            Console.Write(">>>>>>");
          var name = Console.ReadLine();
            A.Speak("Hello " + name );
            A.Speak("How are you today?");
            A.Speak("Hello {0}, How are you today", name);

        }
    }
}

问题在于:

A.Speak(“你好{0},你今天好吗”,姓名);

Speak部分有错误

3 个答案:

答案 0 :(得分:4)

我没有看到任何接受两个字符串的overload of the Speak() method。所以你不能把它传给两个字符串。看起来您希望使用string.Format()创建单个字符串,所以请执行以下操作:

A.Speak(string.Format("Hello {0}, How are you today", name));

答案 1 :(得分:1)

在我看来,你有两个选择。

正如大卫在答案中建议的那样,你可以使用:

A.Speak(string.Format("Hello {0}, how are you today?", name));

您可以做的另一件事情如下:

A.Speak($"Hello {name}, how are you today?");

希望这有帮助!

答案 2 :(得分:0)

由于SpeechSynthesizer类的重载Speak()方法没有接受两个string类型的参数,可能你可以尝试这样:

A.Speak(String.Format("Hello {0}, How are you today", name)); 

此处String.Format会为您提供格式化字符串作为Speak()

的输入