加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB.NET如何命名与其类型相关的变量?

发布时间:2020-12-17 07:30:27 所属栏目:百科 来源:网络整理
导读:只是想知道每个人用什么来命名与已经描述的类有关的变量? 例如: Dim customersData as New CustomersDataDim customersCollection as CustomersCollectioncustomersCollection = customersData.GetAll() 上面似乎没有任何设置规则在C#中是可以的但在VB中没
只是想知道每个人用什么来命名与已经描述的类有关的变量?

例如:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读