在VB.NET中声明数组的首选语法是什么? [英] What is the preferred syntax for declaring an array in VB.NET?

查看:98
本文介绍了在VB.NET中声明数组的首选语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下选项之间,这是在VB.NET中声明数组的首选语法?

Between the following options, which is the preferred syntax for declaring arrays in VB.NET?

  1. Dim numbers1() As Integer

vs.

Dim numbers2 As Integer()

MSDN文章如何:在Visual Basic中初始化数组变量提到了第二个选项作为首选语法:Dim chars2 As Char()...,但是第一个选项在其他文档中似乎更常见.第二个选项可能令人困惑,因为它与调用无参数的构造函数非常相似.

The MSDN article How to: Initialize an Array Variable in Visual Basic mentions the second option as the preferred syntax: Dim chars2 As Char()..., but the first option seems more common in other documentation. The second option might be confusing since it's so similar to calling a constructor with no arguments.

例如

Dim customer As New Customer() ' Initialize a new Customer

类似于:

Dim customer As Customer() ' An uninitialized array of Customers

此问题类似于但与以下问题不同:在VB.NET中声明数组的不同方法.

This question is similar to but different from: Different ways of declaring arrays in VB.NET.

推荐答案

我会在这里鸣叫.

我在代码中看到的样式1比样式2更多,但是在属性方面,语法上存在一些细微的奇异之处.

I've seen more of style 1 in code than style two, however there are some minor odd inconsistencies with syntax when it comes to properties.

我的理论是,首选括号后的原因是使其与声明数组属性更加一致

My theory is the reason the parentheses after is preferred is to make it more consistent with declaring a property that is an array

Public Property x As Integer() 'is an array
Public Property y() As Integer 'is NOT an array

话虽这么说...使用列表:)

That being said...use Lists :)

这篇关于在VB.NET中声明数组的首选语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆