I have:
Dim arr() As String = {"one","two","three"}
I want a new array, sub, containing {“one”, “three”} only. What is the best method to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For this particular case, the simplest option is just to list the two items you want to copy:
In the general case, if you want to take the first item, skip one item, and then take all the rest, an easy option would be to use the LINQ extension methods:
It yields
{"one"}(arr.Take(1))Concat){"three"}(arr.Skip(2))ToArray())Documentation: