0

In VB.net, is there a way to assign values to an array of structure in a single line? For example if I have an array of structure like this:

Public Structure CommandInfo
    Public CommandChar As Char
    Public CommandType As String
    Public Description As String    
End Structure
Public CommandSet(NumCommands - 1) As CommandInfo

Is there a way to assign values to the array like this:

CommandSet(0)={"C", "Initialization", "Initialize pump motor"}

Otherwise, I've been having to do a line of code for each structure element for each array element--it's a little ugly. Thanks!

1
  • Note that if you write your own collection with a custom Add routine taking three arguments, you can array syntax like {{"C", "Initialization", "..."}, {"D", "Deletion", "..."}} etc. As a small aside, I'd suggest you turn Option Strict On. You should need to specify the character argument as "C"C. Commented Jun 28, 2021 at 13:47

1 Answer 1

1

Try this:

CommandSet(0) = New CommandInfo With {.CommandChar = "C", .CommandType = "Initialization", .Description = "Initialize pump motor"}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.