如何将其他命名空间导入到 Visual C# 中?

发布于 2025-01-06 22:59:10 字数 398 浏览 0 评论 0原文

抱歉,如果我的问题看起来有点幼稚,但我找不到答案。我想在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天旳寂寞 2025-01-13 22:59:10

您需要设置对包含您要使用的代码库的 DLL 的引用。据推测这是 SDK 的一部分,所以是的,您应该下载它。然后,在 Visual Studio 中

  • 打开解决方案资源管理器
  • ,打开要使用库的项目
  • ,右键单击该项目的引用节点,
  • 选择“添加引用”
  • ,导航到并选择 dll

成功添加引用后,VS 应该识别 using 指令(以及您在程序集中使用的任何类型)。

请注意,引用的是程序集;程序集与命名空间不同。初学者经常混淆两者。不同程序集中定义的类型可以位于同一命名空间中; BCL 有数十个这样的例子。

此外,“using”指令不会导致加载任何内容或类似的内容;它只允许您指定类型而不完全限定名称。事实上,可以在不使用 using 指令的情况下使用 C# 进行编码。例如,以下代码文件是等效的:

using System.Collections.Generic;
public static class Collector
{
    public static ICollection<T> Collect(IEnumerable<T> enumerable)
    {
        return new List<T>(enumerable);
    }
}

AND

public static class Collector
{
    public static System.Collections.Generic.ICollection<T> Collect(System.Collections.Generic.IEnumerable<T> enumerable)
    {
        return new System.Collections.Generic.List<T>(enumerable);
    }
}

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

  • open the solution explorer
  • open the project where you want to use the library
  • right-click the references node for that project
  • choose "add reference"
  • navigate to and select the dll

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:

using System.Collections.Generic;
public static class Collector
{
    public static ICollection<T> Collect(IEnumerable<T> enumerable)
    {
        return new List<T>(enumerable);
    }
}

AND

public static class Collector
{
    public static System.Collections.Generic.ICollection<T> Collect(System.Collections.Generic.IEnumerable<T> enumerable)
    {
        return new System.Collections.Generic.List<T>(enumerable);
    }
}
送舟行 2025-01-13 22:59:10

下载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.

陌上芳菲 2025-01-13 22:59:10

为了利用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文