ASP.net c#,我怎么知道该使用什么?
我一直在网上浏览 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当我遇到这种情况时,通常我会在 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.
如果它们不包含它们,您可以按顺序遵循此列表:
If they don't include them, you can follow this list in order:
如果代码示例使用项目默认引用的程序集,则可以将鼠标悬停在类名称上并单击 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.
如果您正在 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.
我同意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.