为什么Visual Studio中不会默认创建一个公共类? [英] Why Visual Studio doesn't create a public class by default?
问题描述
在Visual Studio中,当你添加一个新的类,它总是以没有修饰符创建,这使得内部类
In Visual Studio when you add a new class, it always created with no modifiers and that makes class internal.
class MyClass
{
}
我想$我的类在默认情况下是公共之一创建p $ PFER。
I would prefer that my class by default is created as public one.
为什么内部默认?
你会preFER?
推荐答案
制作类内部
默认情况下,使我感觉良好:保持阴部自己,只有明确地揭露这确实需要部分被暴露:一切只是实现的细节,应该是不可见到外面的世界。
Making class internal
by default makes perfect sense to me: keep your privates to yourself and only explicitly expose parts which really need to be exposed: everything else is just implementation details and should not be visible to the outside world.
如果你想测试你的内部
类,.NET 2.0起引入了一个名为新属性<一个href=\"http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx\">InternalsVisibleToAttribute,这
In case you want to test your internal
classes, .NET 2.0 onwards introduces a new attribute called InternalsVisibleToAttribute, which
指定类型的范围仅限于当前组件通常都是可见的另一个组件可见。
Specifies that types that are ordinarily visible only within the current assembly are visible to another assembly.
如果这真的惹恼了你,看的%ProgramFiles%\\微软的Visual Studio 8 \\ Common7 IDE \\的ItemTemplate \\ CSHARP \\ 1033 \\ Class.zip
。这是你可以改变,以满足您的需要的模板。 ReSharper的也有类似的功能,但它是从日UI内直接访问。
If this really annoys you, see %ProgramFiles%\Microsoft Visual Studio 8\Common7 IDE\ItemTemplates\CSharp\1033\Class.zip
. This is a template which you can change to suit your needs. ReSharper has similar capability, but it's directly accessible from within th UI.
这篇关于为什么Visual Studio中不会默认创建一个公共类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!