简体   繁体   中英

What is the VB equivalent to this C# code?

I have the following line in C#:

test.testMethod.Foreach(x => x.testMethod2.Add(test_arg));

What would be the equivalent in VB?

I tried to do x => x.testMethod2.Add but it is not allowing me to.

This is called lambda expression .
An appropriate equivalent in vb.net will be

Sub(x) x.testMethod2.Add(test_arg)

You are basically using Function in case you are are creating expression function and Sub in case you are creating expression subroutine. See Lambda Expressions (Visual Basic) for more details.

It's a lambda expression . The VB equivalent to that C# lambda expression would be:

Sub(x) x.testMethod2.Add(test_arg)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM