English 中文(简体)
C# 代码样式: 从“ 此” 转换为“ 暗核” [已关闭]
原标题:C# Code Style: Switching from "this." prefix to "underscore" [closed]
Closed. This question is opinion-based. It is not currently accepting answers.

想要改进这个问题吗? 更新问题,以便用

Closed 5 years ago.

我使用“这个”前缀已有两年左右(StyleCop SA1102 规则 ) 。 但现在我改变主意,用“下面”前缀来固定和实例私人字段,删除“这个 ” 前缀。

在这里,我的理由 从"这个" 转换为"下面":

  1. Breaks Easily: Nobody in your team will always use "this." prefix so when you see a project which followed this style you will not see "this." prefix for all instance members.
  2. Useless Distinguish: What is the benefit of distinguishing between instance and static fields? Do you ever gain anything of that?
  3. Noise : If you take care of using "this." prefix, you ll see "this" every where. For instance we had 77 times of "this" keyword in a class but after changing our style we just have 9 underscores and I think the code is more readable (you can easily follow the code logic).
  4. Razor: It seems ugly to use "this." prefix in the Razor C# codes. For instance you will have "@this.Html.Something" instead of "@Html.Something". And we like a general rule to apply on all of our C# codes everywhere.

你有什么想法吗?

忽略StyleCop SA1102规则(“ 此” ), 使用“ underscore” 前缀来区分分类字段是否合理?

最佳回答

你们所有的观点都将适用于强调(这需要强制实施,而不是那么有用,等等),如果你们把77这个修改为9——你们也可以用9这个,我肯定。

了解这是一例还是静态场/财产 在多行环境中是非常有用的。

然而,当我看到这一点时,我确切地知道这意味着什么;用强调。我可以猜想,但此时此刻,这真的取决于你有多一贯。

我个人经常(并非总是)用这个来区分本地变数与类属性,

归根结底,这只是一个建议, 如果你和你的团队对强调这一点感到自在的话,使用它。

问题回答

我不认为区分静态和实例成员是毫无用处的。它取决于你大部分时间的工作代码(多读或只是与线条无关的代码 ) 。 “ 这 ” 给出了使用的成员的直截了当的语义, 事实上您个人不需要这一点在这里并不重要。 由多个团队开发的大型企业应用程序从简单的可读性改进( 如“ 这样 ” ) 中受益匪浅。

更多细节





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签