Yugal Jindle Yugal Jindle - 2 years ago 222
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?

Answer Source

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download