copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
Beispiel: VB .Net - Array redimensionieren
'
Option Explicit On
Option Strict Off

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim arr(4) As Integer
        arr(0) = 1200
        arr(1) = 1300
        arr(2) = 1400
        arr(3) = 1500
        arr(4) = 1600

        For n As Integer = 0 To arr.GetUpperBound(0)
            Me.ListBox1.Items.Add(arr(n).ToString())
        Next

        Dim NewArray As Array = Me.[ReDim](arr, 3)
        For n As Integer = 0 To NewArray.GetUpperBound(0)
            Me.ListBox2.Items.Add(NewArray(n).ToString())
        Next
    End Sub

    Private Function [ReDim](ByVal SourceArray As Array, ByVal NewSize As Integer) As Array
        Try
            Dim tp As Type = SourceArray.GetType().GetElementType()
            Dim Result As Array = Array.CreateInstance(tp, NewSize)
            Array.Copy(SourceArray, 0, Result, 0, Math.Min(SourceArray.Length, NewSize))
            Return Result
        Catch
            Return Nothing
        End Try
        Return Nothing
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        Me.CenterToScreen()
    End Sub
End Class
Sourcecode Visual Basic