How can I convert a single value into an array with one element?

I call a method that takes an array of integers representing the identifiers of the records to be written:

service.Delete(IDArray) 

However, I want to delete only one entry, so I have only one value. Obviously, I could do something like this:

 Dim IDArray(0) as Integer IDArray(0) = ID service.Delete(IDArray) 

However, it looks pretty shreds. Is there a neat way to do this on the same line with some kind of clever array syntax?

+6
source share
1 answer

This is pretty neat:

 service.Delete(New integer(0){ID}) 

and, as Domink suggests, this is even more neat (although I like to be explicit):

 service.Delete({ID}) 

Check the documentation .

+5
source

Source: https://habr.com/ru/post/954568/


All Articles