以下是我的场景。我需要调用 using List.Foreach(addressof fn)
。但似乎我们需要将对象作为 list 类型和该 function 传递fn(Type of List as Arg)
。我们可以有另一个参数吗?
员工类
Class Employee
public string Name
public String DisplayName
End Class
--
Dim lstEmployee As New List(Of Employee)
Sub Main()
LoadEmployee()
PrintNames()
Update(5)
End Sub
Shared Sub PrintNames()
names.ForEach(AddressOf Print) ' This will be working fine.
End Sub
Shared Sub Update(Byval int as integer)
names.ForEach(AddressOf UpdateEmpName) ' Not possible
End Sub
Shared Sub LoadNames()
lstEmployee.Add(new Employee with{.Name="Bruce"})
lstEmployee.Add(new Employee with{.Name="Alfred"})
lstEmployee.Add(new Employee with{.Name="Tim"})
lstEmployee.Add(new Employee with{.Name="Richard"})
End Sub
Shared Sub Print(ByVal s As Employee)
Console.WriteLine(s.Name)
End Sub
Shared Sub UpdateEmpName(ByVal s As Employee. ByVal i as integer)
s.DisplayName= "EIN" +i+"-"+s.Name
End Sub
那可能吗 ?. 我正在使用.net 3.5