VS.NET默认为私有类 [英] VS.NET defaults to private class

查看:83
本文介绍了VS.NET默认为私有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Visual Studio在C#中将新类声明为私有类?我几乎总是将它们切换为公开,我是疯了吗?

Why does Visual Studio declare new classes as private in C#? I almost always switch them over to public, am I the crazy one?

推荐答案

默认情况下,对于C#语言说明符而言,私有访问似乎是一个合理的设计选择.

Private access by default seems like a reasonable design choice on the part of the C# language specifiers.

一个好的通用设计原则是使所有访问级别都尽可能严格,以最大程度地减少依赖性.如果您开始尽可能严格地限制并让开发人员采取一些措施使类或成员更加可见,那么最终访问错误级别的可能性就较小.如果某些东西公开性不如您所需要,那么当您遇到编译错误时,这立即显而易见,但是发现比应有的可见性更高的东西并不容易.

A good general design principle is to make all access levels as restrictive as possible, to minimize dependencies. You are less likely to end up with the wrong access level if you start as restrictive as possible and make the developer take some action to make a class or member more visible. If something is less public than you need, then that is apparent immediately when you get a compilation error, but it is not nearly as easy to spot something that is more visible than it should be.

这篇关于VS.NET默认为私有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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