Yugal Jindle Yugal Jindle - 6 months ago 50
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,
sub
, containing {"one", "three"} only. What is the best method to do this?

Answer

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())

Documentation: