我在Visual Studio 2019中找不到System.Media命名空间 [英] I can't find the System.Media namespace in Visual Studio 2019
问题描述
编辑-答案:感谢@LexLi和@Amy,我找到了解决方案;我不小心创建了.NET Core控制台应用程序,而不是.NET Framework.当我将其重新制成.NET Framework应用程序后,便可以使用"System.Media".
Edit - ANSWER: I found the solution thanks to @LexLi and @Amy; I accidentally created a .NET Core console application instead of .NET Framework. Once I remade it as a .NET Framework app it had "System.Media" available.
我对C#的学习相对较新(仅几个星期),但是我正尝试制作一个控制台应用程序文字游戏,并且我使用了一种打字机方法来将消息打印到显示器上. /p>
I'm relatively new (only a few weeks in) to learning C#, but I'm trying to make a console application text game, and I have a typewriter method I'm using to print messages to the display.
public static void typewriter(string s)
{
// This method types strings out slowly.
for (int i = 0; i < s.Length; i++)
{
Console.Write(s[i]);
Thread.Sleep(50);
}
}
我想在键入每个字符时添加声音(我已经有打字机声音了).我看到有人推荐了System.Media中的SoundPlayer类.看起来像这样:
I want to add a sound when each character is typed (I have the typewriter sound already). I saw some people recommend the SoundPlayer class located in System.Media. It would look something like this:
SoundPlayer typewriter = new SoundPlayer();
typewriter.SoundLocation = Environment.CurrentDirectory + "/typewriter.wav";
我的问题是,我似乎无法访问System.Media
My problem is, I don't seem to have access to System.Media
如果键入using System.(et cetera)
,则Intellisense不会将媒体"显示为可用选项.我正在使用Visual Studio 2019并具有.Net Framework版本4.8之类的东西
If I type using System.(et cetera)
, Intellisense does not show Media as an available option. I am using Visual Studio 2019 and have .Net Framework Version 4.8 something
我如何访问System.Media?
How can I get access to System.Media?
这是一张带有一些信息的照片,用于显示我的.Net框架,而Visual Studio无法识别SoundPlayer();
Here's a photo with some info to show my .Net framework and that Visual studio doesn't recognize SoundPlayer();
推荐答案
检查MSDN中有关该名称空间的文档.确定其所在的程序集.然后添加对该程序集的引用.
Check MSDN for documentation on that namespace. Identify which assembly its located in. Then add a reference to that assembly.
Google"MSDN system.media" .从该命名空间中选择一个类.我将使用 SoundPlayer .
Google "MSDN system.media".. Pick a class from that namespace. I'll use SoundPlayer.
文档说该类位于Assemblies:
System.dll, System.Windows.Extensions.dll
中.
The documentation says that class is located in Assemblies:
System.dll, System.Windows.Extensions.dll
.
因此 查看全文