如何为VB.NET中的变量命名,使其与类型紧密关联?

2026-05-08 12:373阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计507个文字,预计阅读时间需要3分钟。

如何为VB.NET中的变量命名,使其与类型紧密关联?

想了解每个人用什么来命名变量,以及已描述的变量有哪些相关变量吗?例如:Dim customersData As New CustomersData, Dim customersCollection As CustomersCollection, customersCollection=customersData.GetAll() 上面的代码似乎没有相关变量。

只是想知道每个人用什么来命名与已经描述的类有关的变量?

例如:

如何为VB.NET中的变量命名,使其与类型紧密关联?

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.

标签:变量只是

本文共计507个文字,预计阅读时间需要3分钟。

如何为VB.NET中的变量命名,使其与类型紧密关联?

想了解每个人用什么来命名变量,以及已描述的变量有哪些相关变量吗?例如:Dim customersData As New CustomersData, Dim customersCollection As CustomersCollection, customersCollection=customersData.GetAll() 上面的代码似乎没有相关变量。

只是想知道每个人用什么来命名与已经描述的类有关的变量?

例如:

如何为VB.NET中的变量命名,使其与类型紧密关联?

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.

标签:变量只是