Tips and tricks for .NET using ASP and VB code.

Convert integer array to string array

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim IntegerArray As Integer() = {1, 2, 3}
        Dim TextArray As String() = ToStringArray(IntegerArray)
        Dim JoinedNumbers As String = Join(TextArray, ", ")
    End Sub

    Protected Function ToStringArray(IntegerArray() As Integer) As String()
        Dim NumbersText() As String = Array.ConvertAll(IntegerArray, New Converter(Of Integer, String)(AddressOf Convert.ToString))
        Return NumbersText
    End Function

No comments:

Post a Comment

Search This Blog