I can't find the System.Media namespace in Visual Studio 2019

大兔子大兔子 提交于 2020-01-05 06:31:24

问题


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.

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

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

My problem is, I don't seem to have access to System.Media

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

How can I get access to System.Media?

Here's a photo with some info to show my .Net framework and that Visual studio doesn't recognize SoundPlayer();


回答1:


Check MSDN for documentation on that namespace. Identify which assembly its located in. Then add a reference to that assembly.

Google "MSDN system.media".. Pick a class from that namespace. I'll use SoundPlayer.

The documentation says that class is located in Assemblies: System.dll, System.Windows.Extensions.dll.

So add a reference to one of those assemblies.



来源:https://stackoverflow.com/questions/58938947/i-cant-find-the-system-media-namespace-in-visual-studio-2019

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!