0

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.

sloth
  • 99,095
  • 21
  • 171
  • 219
user1180223
  • 111
  • 8
  • 2
    Side note: those tools seem to always fail on delegates, lambda expressions, events and the like... – sloth Aug 16 '12 at 09:06
  • 1
    They do, these converters invariably produce junk on the kind of statements where you need them the most. The Sub keyword in a lambda expression isn't supported until VB10. The fall-back is AddressOf with a little private method. – Hans Passant Aug 16 '12 at 09:33

1 Answers1

3

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"))
sloth
  • 99,095
  • 21
  • 171
  • 219