Use of ForEach in vb.net

Satyapriyanayak
Posted by Satyapriyanayak under VB.NET category on | Points: 40 | Views : 905
Public Class Form1
Inherits System.Windows.Forms.Form

Dim a As New ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

a.Add("raj")
a.Add("ravi")
a.Add("rahul")
a.Sort()


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim s As String
For Each s In a
Label1.Text += s + vbCrLf
Next

End Sub
End Class

Public Class Form2
Inherits System.Windows.Forms.Form

Dim a As New Hashtable

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

a.Add("a1", "Raj")
a.Add("a2", "Ravi")
a.Add("a3", "Rahul")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim x As String
For Each x In a.Keys
Label1.Text += x + vbCrLf
Next
For Each x In a.Values
Label1.Text += x + vbCrLf
Next

End Sub

Comments or Responses

Login to post response