C#字符串文件路径问题

我正在尝试为SoundPlayer对象设置文件路径

如果我的主项目文件夹中有一个声音文件夹。 我该如何发送

 Soundplayer test = new Soundplayer("Sounds/Fireball.wav"); 

文件相对于主项目的位置并不重要。 重要的是声音文件在部署/调试时相对于您的应用程序的位置。 如果它将具有与主.exe路径相同的相对路径,那么您可以使用以下内容。

 var root = typeof(Program).Assembly.Location; var soundPath = Path.Combine(root, @"sounds\Fireball.wav"); var test = new SoundPlayer(soundPath); 

你有没有试过@"Sounds\Fireball.wav"的路径?

如果用完Visual Studio,当前工作目录将是bin\Debug ,因此有问题的文件需要位于bin\Debug\Sounds\Fireball.wav

另外,正如其他人提到的那样,你应该使用反斜杠\而不是forwardslash /