问题描述
我了解使用驼峰式变量名的原因,但我一直想知道为什么要使用驼峰式方法名?为什么是toString()而不是ToString()?它有什么作用?
I understand the reason to camel case variable names, but I've always wondered why you would camel case a method name? why is it toString() and not ToString()? What purpose does it serve?
推荐答案
很多约定说您将类型的首字母大写(类,结构,枚举等),否则使用小写字母(函数,成员等) ).
A lot of conventions say you capitalize the first letter of types (classes, structs, enums, etc.), and use lowercase otherwise (functions, members, etc.).
如果遵循该约定,则只需看一下MyStruct.MyType
表示嵌套类型,MyStruct.myData
表示某种形式的数据,而MyStruct.myFunc()
表示函数调用即可.
If you follow that convention, you can then tell just by looking that MyStruct.MyType
refers to a nested type, and MyStruct.myData
refers to some form of data, and MyStruct.myFunc()
refers to a function call.
这篇关于骆驼案例方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!