Pages

Monday, November 23, 2015

Array Conversion in VB.Net

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.ObjectByVal e As System.EventArgsHandles 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.ObjectByVal e As System.EventArgsHandles 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.ObjectByVal e As System.EventArgsHandles 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
 

No comments:

Post a Comment