Yugal Jindle Yugal Jindle - 8 months ago 83
Vb.net Question

How to get sub-array from larger array in VB.NET?

I have:

Dim arr() As String = {"one","two","three"}

I want a new array,
, containing {"one", "three"} only. What is the best method to do this?


An easy option would be to use the LINQ extension methods:

Dim arr2 = arr.Take(1).Union(arr.Skip(2)).ToArray()

It yields

  • "one" (arr.Take(1))
  • combined with (Union)
  • "three" (arr.Skip(2))
  • into a new array (ToArray())