Array Conversions in VB.NET

In this article I will explain you about the Array Conversions in VB.NET
  • 2117

Array is a construct which store data and we can access that data by using numeric index or subscript and by using array you can reduce you code length your application become shorter. There is a Array class in the system namespace arrays in Visual Basic .Net inherit from this class.The Type property of Array objects provides information about array type declarations. Array objects with the same array type share the same Type object, so the array is said to be homogenous. But you can store wrapper classes as objects with aggregation or composition, which can store or link references to other objects.

The below example shows conversion of string array into character array.

EXAMPLE CODE

    Public Class Form1
        Dim ChArray As Char()
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            RichTextBox1.Text =
"Sample Text"
            Me.Text = "character Array To String"
            Button1.Text = "Char Array"
            Button2.Text = "String Array"
            Button2.Enabled = False
        End
Sub
   
        Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If RichTextBox1.Text.ToString().Length > 0 ThenButton2.Enabled = True
                ChArray = RichTextBox1.Text.ToCharArray()
                RichTextBox2.Text =
""

            For i As Integer = 0 To ChArray.Length - 1
                RichTextBox2.Text += ChArray(i).ToString()
            Next
            End
If
        End
Sub

        Private
Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            RichTextBox1.Text =
""
            For i As Integer = 0 To ChArray.Length - 1
                RichTextBox1.Text += ChArray(i).ToString()
            Next
        End
Sub
    End
Class

OUTPUT

7.gif
 

CONCLUSION

Hope this article would have helped you in understanding the Array Conversions in VB.NET. See other articles on the website on VB.NET Heaven.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.