对于什么,我应该庆祝,如果他们已经是私有变量私有? [英] What for should I mark private variables as private if they already are?

查看:131
本文介绍了对于什么,我应该庆祝,如果他们已经是私有变量私有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在C#中的所有字段都是私有的默认情况下,如果没有标明,否则。

As far as I know, in C# all fields are private for default, if not marked otherwise.

class Foo
{
  private string bar;
}

class Foo
{
  string bar;
}

我想这两个声明都是平等的。

I guess these two declarations are equal.

所以我的问题是:什么我应该标记私有变量私人如果他们已经是私人

So my question is: what for should I mark private variables as private if they already are private?

推荐答案

我一直在篱笆上有关这一点的同时。我曾经主张离开它隐含的,但现在我觉得我放倒走向摆明。

I've been on the fence for a while about this. I used to argue for leaving it implicit, but now I think I'm tipped over towards making it explicit.

离职原因是隐含的:

  • 这意味着有非私有成员(或任何与比默认更多的访问)一个较大的差异;看完code
  • 在当前这个突出的区别
  • It means there's a bigger difference for non-private members (or anything with more access than the default); this highlights the difference when reading the code

原因摆明:

  • 在一些开发者可能不知道的默认值:摆明意味着它清楚的每个人
  • 这说明你已经积极地做出了决定,而不是仅仅留到默认

这些后点基本上是那些由埃里克利珀当我们讨论它制成前一阵子。

These latter points are basically the ones made by Eric Lippert when we discussed it a while ago.

这篇关于对于什么,我应该庆祝,如果他们已经是私有变量私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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