I have the following line of code in c#.

Check.ThatIsNotAnEmptyString(line1, () => { throw new InvalidAddressException("An address must have a street"); });

I am having difficulty converting it to vb.net.

I used the conversion tool 'www.developerfusion.com' but it produces the following piece of code.

Check.ThatIsNotAnEmptyString(line1, Function() Throw New InvalidAddressException("An address must have a street") End Function)

It complains on the word 'Throw' saying expression expected.

Can anyone tell me if converting this to vb.net is possible.

有帮助吗?

解决方案

You have to use Sub, since the function has no return value (like void in C#).

Also, since the function is on one line, you don't need to have a End Sub/Function, which is only needed on multiline functions (and was added in .Net 4.0).


So your code should read:

Check.ThatIsNotAnEmptyString(line1, Sub() Throw New InvalidAddressException("An address must have a street"))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top