关于在公共区域添加命名空间

发布于 2024-11-23 23:08:02 字数 436 浏览 3 评论 0原文

我们总是在 win 应用程序中的每个表单的顶部添加命名空间

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Business;
using System.Data.SqlClient;
using Business;

并且大多数命名空间在大多数表单中都很常见,但在 ASP.NET 中,有一项规定只能在 web.config 文件中添加一次命名空间。所以我们不必在所有网络表单中添加它,这样可以节省时间。所以我只需要知道我们的胜利应用程序是否有任何相同的规定。如何实现它。谢谢

we always add namespace at the top of the every form in win apps

like

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Business;
using System.Data.SqlClient;
using Business;

and most of namespace are common in most form but in asp.net there is a provision to add namespace only once in web.config file. so we dont have to add it in all web form and it save time. so i just need to know is there any same sort of provision for our win apps. how to achieve it. thanks

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

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

发布评论

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

评论(2

甩你一脸翔 2024-11-30 23:08:03

不,您的 WinForm 应用程序没有任何类型的规定,而 ASP.NET 应用程序则使用 web.config 中的 部分。另请注意,这仅适用于 .aspx 页面,不适用于 C# 背后的代码。在 C# 中,您必须添加正确的 using 语句,以便将要使用的类型引入作用域。

No, there isn't any sort of provision for your WinForm applications as there is for ASP.NET applications using the <namespaces> section in web.config. Also note that this applies only to .aspx pages and not code behind C#. In C# you have to add proper using statements in order to bring the types you want to use into scope.

雨落星ぅ辰 2024-11-30 23:08:03

一种方法是将标准 using 指令添加到通用模板中。

您没有提及您正在使用哪个版本的 Visual Studio,但在 VS2010 中您可以在以下位置找到模板:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

更改 zip 中的 Class.cs 文件以默认包含您想要的用法。

唯一的缺点是它是针对每台机器的 - 因此您需要在每台开发人员计算机上执行此操作 - 尽管我敢说您可以使用 Active Directory 来推出它(这是 serverfault.com 的问题)。

我相信也可以设置团队模板 - 但这不是我尝试过的。更多信息请访问:

http://msdn.microsoft.com/en-us/杂志/cc188697.aspx

One method is to add the standard using directives into the common templates.

You don't mention which version of visual studio you are using but in VS2010 you can find the templates in:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

Change the Class.cs file in the zip to include the usings you want by default.

The only downside to this is that it is per machine - so you will need to do it on each developers computer - although I daresay you could roll it out with Active Directory (that's a question for serverfault.com).

I believe it also possible to set up team templates - but it's not something I have tried. More information available here:

http://msdn.microsoft.com/en-us/magazine/cc188697.aspx

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