什么是用C#命名私人和私人静态方法的最佳实践? [英] What is the best practice for naming private and static private methods in C#?
问题描述
我试图弄清楚什么是命名私有方法和在C#中的私人静态方法的最聪明的办法
I'm trying to figure out what is the smartest way to name private methods and private static methods in C#.
背景:
我知道,对于私有成员的最佳做法是下划线前缀+驼峰。你可以跟我争论这一点,但相信我,我已经看到了从遵守这个约定铁杆利弊足够的代码,它是熟练的行业标准。
Background: I know that the best practice for private members is underscore-prefix + camelcase. You could argue this with me, but trust me I've seen enough code from hardcore pros that follow this convention, it is the skilled industry standard.
我也知道,帕斯卡情况下是公共方法的行业标准。但我所看到的测试样式命名的组合(即method_must_return_false_occasionally)帕斯卡的情况下,首字母大写,并强调前缀+大小写混合,私人和私人静态方法。
I also know that pascal case is the industry standard for public methods. But I have seen a combination of test style naming (ie. method_must_return_false_occasionally ) to pascal case, camelcase, and underscore-prefix + camelcase, for private and private static methods.
但是,什么是在C#中的私人和私有静态方法命名的最佳做法的风格?
But what is the best practice style for private and private static method naming in C#?
如果有一些是从一些私人的方法使用,而不是别人的某些风格,我可以明白,只是解释。
If there are certain styles that are used from some private methods and not others, I can understand that, just explain.
感谢您的阅读。
推荐答案
Check out the Microsoft's Naming Guidelines and Brad Abram's Style Guide
他们说,所有的方法应该是PascalCase
They say that all methods should be PascalCase
public void DoWork() {}
private void StillDoWork() {}
private static void ContinueToDoWork() {}
这篇关于什么是用C#命名私人和私人静态方法的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!