Hi,
I am new to .net.
Please give me some guidance to the following problem.
I have to fill a listbox with the results avaiable by querying windows service using ServiceController.GetServices method
I will list down the code I used.
I know using foreach to fill the listbox.
But I want to use array.foreach with lambda or delegates.(inline function)
I don't have any clue.
Please helpme.
My VB.Net code
Public class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim services As ServiceProcess.ServiceController() = ServiceProcess.ServiceController.GetServices
'For Each s In services
'ListBox1.Items.Add(s.DisplayName.ToString)
'Next
' Array.ForEach(services,delegate(s as serviceprocess.servicecontroller) listbox1.items.add(s.displayname)o
Array.ForEach(services, AddressOf ListBoxAdd) -- This line I understood
'NO IDEA HOWTO USE DELEGATES OR LAMBDA
' Array.ForEach(services,delegate(s as serviceprocess.servicecontroller) listbox1.items.add(s.displayname)
End Sub
Public Sub ListBoxAdd(ByVal s As ServiceProcess.ServiceController)
ListBox1.Items.Add(s.DisplayName)
End Sub
End
Class
I am new to .net.
Please give me some guidance to the following problem.
I have to fill a listbox with the results avaiable by querying windows service using ServiceController.GetServices method
I will list down the code I used.
I know using foreach to fill the listbox.
But I want to use array.foreach with lambda or delegates.(inline function)
I don't have any clue.
Please helpme.
My VB.Net code
Public class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim services As ServiceProcess.ServiceController() = ServiceProcess.ServiceController.GetServices
'For Each s In services
'ListBox1.Items.Add(s.DisplayName.ToString)
'Next
' Array.ForEach(services,delegate(s as serviceprocess.servicecontroller) listbox1.items.add(s.displayname)o
Array.ForEach(services, AddressOf ListBoxAdd) -- This line I understood
'NO IDEA HOWTO USE DELEGATES OR LAMBDA
' Array.ForEach(services,delegate(s as serviceprocess.servicecontroller) listbox1.items.add(s.displayname)
End Sub
Public Sub ListBoxAdd(ByVal s As ServiceProcess.ServiceController)
ListBox1.Items.Add(s.DisplayName)
End Sub
End
Class