简体   繁体   中英

Parenthesis after field name in VB.Net

I always work in C#, but I've been asked to work on a legacy VB.Net solution. In the legacy code, I am seeing this:

Private transactionListField() As TransactionInfoForStatement

This makes no sense to me! If it was C#, I'd expect this:

private List<Transaction> _transactions;

Can someone please explain to me what that VB code does? The parenthesis after the name makes me think it is calling a method, but when I Go To Definition in Visual Studio, I just end up on the same line!

That's an array declaration, you could also use this syntax that i prefer:

TransactionListField As TransactionInfoForStatement() ' array which is declared but Nothing

Arrays or indexers always use () in VB.NET as opposed to C# where you use [] .

There's one advantage if you use the braces-first-syntax, you can specify the size:

TransactionListField(10) As TransactionInfoForStatement ' array that contains 11 Nothing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM