在C#中使用集中关键词 [英] Centralized Using keyword in C#

查看:154
本文介绍了在C#中使用集中关键词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,使一个头式的C#文件?

Is there a way to make a single "header" type file in C#?

在C ++中,你有类似的东西,把所有的Mainheader.h你包括在里面。

In C++ you had something like "Mainheader.h" that had all of your includes in it.

有没有办法做到的C#类似的东西,你必须用你的使用关键字的一个文件中?

Is there a way to do something similar for C# where you had a single file with all of your "using" keywords?

现在我有一大堆的使用如:

使用系统;

使用System.Collections.Generic;
使用System.Linq的
;

使用System.Web.UI程序;

使用
$ B $使用的System.Web b System.Web.UI.WebControls;采用

System.Net.Mail;

Right now I have a bunch of using such as: using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

有没有办法把他们都变成一个头文件的方式?

Is there a way to put them all into a single header file?

推荐答案

不是真的。在mainheader.h的方式工作了C ++,因为头是编译器实际编制,因此称为预处理器指令执行前的字面文本复制和焊膏。

Not really. The "mainheader.h" approach worked for C++ because headers are literally textual copy-and-pastes that compilers executed before actually compiling, hence the term "pre-processor directive".

你可能找到有用的是创建一个包含一些你最常用指令的模板。下面是关于如何做到这一点在Visual Studio 2010中的链接:的http:// MSDN。 microsoft.com/en-us/library/6db0hwky.aspx 。你可以做到这一点在MonoDevelop中为好,但它是一个有点麻烦,直接涉及编辑XML。希望这足以作为一种解决方法。

What you may find useful is to create a template that contains some of your most commonly-used directives. Here's a link on how to do it in Visual Studio 2010: http://msdn.microsoft.com/en-us/library/6db0hwky.aspx. You can do it in MonoDevelop as well, but it's a little trickier and involves editing XML directly. Hope this suffices as a workaround.

这篇关于在C#中使用集中关键词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆