只是想知道每个人用什么来命名与已经描述的类有关的变量? 例如: Dim customersData as New CustomersDataDim customersCollection as CustomersCollectioncustomersCollection = customersData.GetAll() 上面似乎没有任
例如:
Dim customersData as New CustomersData Dim customersCollection as CustomersCollection customersCollection = customersData.GetAll()
上面似乎没有任何设置规则在C#中是可以的但在VB中没有建议(尽管它会编译得很好)我看过像’o'(oCustomersData)这样的前缀以及’my'(myCustomersData)但我不是我确定我也喜欢看过像cd& amp;这样的缩写词. cc这个论点是你所要做的就是将鼠标悬停在变量上以查看类型,但这严重损害了自我文档和可读性.
你的想法是什么人?
我会这样编码:Dim customersData As New CustomersData Dim customers As CustomersCollection customers = customersData.GetAll()
我建议使用变量名称客户,因为我假设这是您将在整个方法中使用的变量,因此它更能描述您正在处理的内容.例如,您可能在以后的代码中有:
For each customer In customers .... Next
Not advised in VB (although it will compile just fine)
我以前没见过这个建议,而且我一直都在使用这种方法.
I have seen prefixes like ‘o’ (oCustomersData) as well as ‘my’ (myCustomersData) but I’m not sure I like either.
我从来没有像这样的变量前缀.我前缀的唯一变量是带有_的类变量;例如_customers
I have also seen abbreviations like cd & cc the argument being that all you have to do is hover over the variable to see the type but this seriously damages self documentation and readability.
你已经提供了答案.没有必要,并且使用像这样的短变量名可读性是有害的.如果使用短变量名称的参数是打字速度,我认为学会正确输入并使用intellisense.