ASP.net c#,我怎么知道该使用什么?

发布于 2024-09-26 11:27:41 字数 187 浏览 6 评论 0原文

我一直在网上浏览 ASP.net c# 的代码示例,但是它们似乎从不列出它们包含哪些命名空间,例如:

using System.Data.SqlClient;
etc etc

我是否遗漏了一些明显的东西,或者我应该确切地知道每个命名空间是什么代码示例需要吗?

I keep coming accross code samples online for ASP.net c#, however they never seem to list which namespaces they include, for example:

using System.Data.SqlClient;
etc etc

Am I missing something obvious or should I be expected to know exactly what namespaces each code example requires?

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

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

发布评论

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

评论(5

夜雨飘雪 2024-10-03 11:27:41

当我遇到这种情况时,通常我会在 MSDN 上搜索该课程。该文档将告诉您哪些名称空间包含该类。

When I'm in that situation, typically I search for the class on MSDN. The documentation will tell you which namespaces contain the class.

一城柳絮吹成雪 2024-10-03 11:27:41

如果它们不包含它们,您可以按顺序遵循此列表:

  • 找到它们位于“空白代码文件”模板中列出的命名空间之一,或者
  • 在 Visual Studio 中您可以单击缺少的类型并按 Shift+F10或 Ctrl+。要获得自动添加 using 语句的选项(如果引用了程序集)
  • ,请使用 Resharper,选择键入并按 alt+enter 让 Resharper 查找命名空间,并将其添加到 usings 中(甚至可能还引用程序集)
  • 转到 MSDN 并搜索名称。
  • 转到 Google 并搜索名称(老实说,我通常在访问 MSDN 之前执行此操作)
  • 向文章作者投诉

If they don't include them, you can follow this list in order:

  • Find that they are in one of the namespaces listed in the "blank code file" template , or
  • In Visual Studio You can click the missing type and press shift+F10 or Ctrl+. To get the option to automatically add the using statement (if the assembly is referenced)
  • With Resharper, Select the type and hit alt+enter for Resharper to find the namespace for you, and add it to the usings (possibly even reference the assembly as well)
  • Go to MSDN and search the name.
  • Go to Google and search the name (honestly, I normally do this before hitting MSDN anyway)
  • Compain to the article author
迷乱花海 2024-10-03 11:27:41

如果代码示例使用项目默认引用的程序集,则可以将鼠标悬停在类名称上并单击 shift+F10,这将自动添加 using 语句。如果该类不在任何引用的程序集中,那么您就不走运了,需要知道该类驻留在哪个程序集中。

快速的谷歌搜索会有所帮助,并且及时您将记住名称空间...当然,如果示例包含名称空间和参考信息是最好的,但大多数情况下它们不包含名称空间。

If code samples use the assemblies that a project references by default, then you can hover on the class name and click shift+F10 which will add the using statement automatically. If the class is not in any of the referenced assemblies then you are out of luck and need to know in what assembly does the class resides.

A quick google search can help, and in time you will memorize the namespaces... Of course its best if samples included the namespace and reference info, but mostly they do not.

永不分离 2024-10-03 11:27:41

如果您正在 Visual Studio 中查看代码,只需将鼠标悬停在您想要的类或对象上,如果该类的程序集存在,您将获得有关它的工具提示,或者您可以通过 google 搜索特定类。例如,如果您想了解更多信息'DataTable'类,只需谷歌一下,你就会知道它是 Syste.Data 命名空间的一部分。

If you are viewing code in Visual studio, just hover mouse over class or object you want and you will get tool tip about it if assemly of that class is present or you can google for particular class.For example if you want to know more about 'DataTable'class, just google it and you will come to know that its part of Syste.Data namespace.

神也荒唐 2024-10-03 11:27:41

我同意OP的观点。必须神奇地“知道”需要什么名称空间似乎非常愚蠢。

我在 C# 之前作为 Java 开发人员花了一些时间,NetBeans IDE 会自动为您解决这些问题。 Ctrl-Shift-I,它将插入您需要的所有包(即命名空间)。如果多个包定义了您要解析的类,则会弹出一个窗口,让您选择所需的类。

VS这么好的产品,居然没有这个功能,我都不敢相信。

I'm with the OP on this one. Having to just magically "know" what namespaces are required seems supremely silly.

I spent some time before C# as a Java Developer, and the NetBeans IDE will resolve these for you automatically. Ctrl-Shift-I, and it will insert all the packages (ie, namespaces) you need. If more than one package defines the class you are resolving, a window pops up and lets you choose which one you want.

For as fine a product as VS is, I am incredulous that this feature is not included.

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