如何将其他命名空间导入到 Visual C# 中?
抱歉,如果我的问题看起来有点幼稚,但我找不到答案。我想在我的 XNA 游戏中使用 DirectInput。我阅读过相关内容,发现这是从 Xbox 360 控制器以外的游戏手柄获取输入的最佳方式。第一步是包含 Microsoft.DirectX.DirectInput 命名空间,但我不太知道如何操作。简单地把它放在我的课程开始是行不通的,Visual C# 无法识别它。
这让我想到我应该下载 DirectX SDK 吗?里面有很多东西,而且文件很大,我如何下载单个命名空间?这可能吗?如果我可以下载单个命名空间,我将该文件放在哪里?
现在你可以看到我脑子里盘旋的所有问题。那么如何让 Visual C# 识别 Microsoft.DirectX.DirectInput 命名空间,以便我可以使用方法、属性和所有这些好东西呢?
谢谢!
Sorry if my question seems a little noobish but I can't find an answer. I would like to use DirectInput for my XNA game. I've read around and it seems this is the best way to get input from a gamepad other than a XBox 360 controller. The first step is to include the Microsoft.DirectX.DirectInput namespace however I don't quite know how. Simply putting it in at the beginning of my class doesn't work, visual C# doesn't recognize it.
This got me thinking should I download the DirectX SDK? There is alot of stuff in there and the file is big how do I just download the single namespace? Is this even possible? If I can download the single namespace where do I put the file?
Now you can see all the questions racking around in my brain. So how do I make visual C# recognize the Microsoft.DirectX.DirectInput namespace so I can use the methods, properties and all that good stuff?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要设置对包含您要使用的代码库的 DLL 的引用。据推测这是 SDK 的一部分,所以是的,您应该下载它。然后,在 Visual Studio 中
成功添加引用后,VS 应该识别 using 指令(以及您在程序集中使用的任何类型)。
请注意,引用的是程序集;程序集与命名空间不同。初学者经常混淆两者。不同程序集中定义的类型可以位于同一命名空间中; BCL 有数十个这样的例子。
此外,“using”指令不会导致加载任何内容或类似的内容;它只允许您指定类型而不完全限定名称。事实上,可以在不使用
using
指令的情况下使用 C# 进行编码。例如,以下代码文件是等效的:AND
You need to set a reference to the DLL containing the code library you'd like to use. Presumably that's part of the SDK, so yes, you should download it. Then, in Visual Studio
Once you've added the reference successfully, VS should recognize the using directive (and any types you've used from the assembly).
Note that references are made to assemblies; assemblies are not the same as namespaces. Beginners often confuse the two. Types that are defined in different assemblies can be in the same namespace; the BCL has dozens of examples of this.
Furthermore, the "using" directive doesn't cause anything to be loaded or anything like that; it just allows you to specify types without fully qualifying the names. In fact, it's possible to code in C# without ever using a
using
directive. For example, the following code files are equivalent:AND
下载SDK。它不会与您的应用程序一起重新分发。但是您开发 DirectX 应用程序所需的一切都将包含在其中。安装后,“添加引用”对话框中将出现新条目。
Download the SDK. It will not be redistributed with your app.. but everything you need to dev DirectX apps will be included in there. When installed there will be new entries in the "Add Reference" dialog.
为了利用 DirectX,您需要下载 SDK。
根本不可能下载其中的一部分。即使是这样,我也绝不会建议这样做。
In order to leverage DirectX you will need to download the SDK.
It is simply not possible to download a part of it. Even if it was, I would never recommend doing that.