如何创建解决方案中可用的任何类的对象

发布于 2024-09-13 22:17:02 字数 189 浏览 2 评论 0原文

我有一个严肃的问题要问你们。我正在开发一个有数百个类的项目。如果我想创建该类的对象,为什么我不能访问所有类。

例如:我有 A、B 和 C 类。

在第 1 页中,我可以创建 A 和 B 的对象,但不能创建 C。当我尝试输入 C 类时,智能感知不起作用。我需要访问 C 类来获取其中使用的一些函数。 我该怎么做才能访问创建 C 类对象?

I have a serious question for you guys. I am working on a project that has hundreds of classes. Why cant i access all classes if i want to create an object of that class.

For example: I have Class A, B and C.

In Page 1, i can create an object of A and B but not C. When i try to type in Class C, the intellisense does not work. I need to access class C to get some of the functions used in it.
What can i do to get access to create objects of class C??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

尸血腥色 2024-09-20 22:17:02

您可能缺少以下任一内容:

  • 程序集引用(对包含类 C 的项目)
  • 包含类 C 的命名空间using 指令

例如,要使用 NetworkStream 类,您需要对 System.dll 程序集的引用,并且通常会有一个像这样的 using 指令:

using System.Net.Sockets;

在需要使用它的类中。您没有有一个using指令 - 您可以显式指定全名 - 但这通常是一个好主意。

现在,类 C 也可能是其所属项目的内部,而您位于不同的项目中 - 这意味着您无权访问它(并且您不意味着到)。或者,例如,您可能正在尝试调用构造函数,但没有任何公开可用的构造函数。

Chances are you're missing either:

  • An assembly reference (to the project containing class C)
  • A using directive for the namespace containing class C

For example, to use the NetworkStream class, you'd need a reference to the System.dll assembly, and you'd usually have a using directive like this:

using System.Net.Sockets;

in the class that needed to use it. You don't have to have a using directive - you can specify the full name explicitly - but it's usually a good idea.

Now it's also possible that class C is internal to the project it's part of, and you're in a different project - which means that you don't have access to it (and you're not meant to). Or perhaps you're trying to call a constructor and there aren't any publicly available ones, for example.

2024-09-20 22:17:02

这听起来像是命名空间问题。您可以将类放入唯一的命名空间中,以避免类之间的命名冲突,并帮助组织代码。查看每个类并确定它驻留在哪个命名空间中。如果它们驻留在不同的命名空间中,您将必须在尝试访问它们的类的顶部放置一个 using 语句。此外,如果某些课程位于不同的物理项目中,您也必须引用它们。希望这有帮助。

享受!

This sounds like a namespace issue. You can put classes into unique namespaces to avoid naming conflicts between classes and also to help organize your code. Take a look at each class and determine what namespace it resides in. If they reside in different namespaces you will have to put a using statement at the top of the class your trying to access them from. Also if some of the class reside in physical different projects you will have to reference them as well. Hope this helps.

Enjoy!

笑脸一如从前 2024-09-20 22:17:02

类 C 很可能不存在于与其他类相同的程序集或命名空间中。仔细检查您的引用和 using 语句,您可能会发现 C 类将可供您使用。

Most likely class C doesn't exist within the same assembly or namespace as the other classes. Double check your references and using statements and you will likely find class C will become available to you.

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