![](/img/trans.png)
[英]Trying to add System.Media namespace to a Visual Studio Code Project
[英]I can't find the System.Media namespace in Visual Studio 2019
編輯 - 答案:感謝@LexLi 和@Amy,我找到了解決方案; 我不小心創建了一個 .NET 核心控制台應用程序,而不是 .NET 框架。 一旦我將它重新制作為 .NET 框架應用程序,它就有“System.Media”可用。
我對學習 C# 相對較新(僅幾周),但我正在嘗試制作控制台應用程序文本游戲,並且我有一種打字機方法用於將消息打印到顯示器。
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 class。 它看起來像這樣:
SoundPlayer typewriter = new SoundPlayer();
typewriter.SoundLocation = Environment.CurrentDirectory + "/typewriter.wav";
我的問題是,我似乎無權訪問 System.Media
如果我using System.(et cetera)
鍵入,Intellisense 不會將媒體顯示為可用選項。 我正在使用 Visual Studio 2019 並擁有 .Net Framework 4.8 版
如何訪問 System.Media?
這是一張帶有一些信息的照片,顯示了 my.Net 框架,並且 Visual Studio 無法識別 SoundPlayer();
檢查 MSDN 以獲取有關該名稱空間的文檔。 確定它位於哪個程序集。然后添加對該程序集的引用。
谷歌“MSDN system.media”。 . 從該命名空間中選擇一個 class。 我將使用SoundPlayer 。
文檔說 class 位於程序集中Assemblies: System.dll, System.Windows.Extensions.dll
因此, 添加對其中一個程序集的引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.