Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a neat way to convert a single value to an array with a single element?

Tags:

arrays

vb.net

I'm calling a method which takes an array of integers representing IDs of records to be deleted:

service.Delete(IDArray)

However I only want to delete a single record so I only have a single value. Obviously I could do something like this:

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

However it looks quite kludgy. Is there a neat way to do this in a single line with some sort of clever array construction syntax?

like image 811
Carl Onager Avatar asked Sep 25 '13 08:09

Carl Onager


1 Answers

This is pretty neat:

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

and, as Dominc suggests, this is even neater (although I like being explicit):

service.Delete({ID})

Check the documentation.

like image 119
Robin G Brown Avatar answered Oct 13 '22 11:10

Robin G Brown