I am trying to move some of my C# code into VB. When I run the C# code thru Telerik's translator it spits out the VB code below. The VB code will not compile and gives and error on the "a.Remove()" section. The error is
"Expression does not produce a value"
What would the correct code be to remove the "script" and "a" tags so the VB code works the same as the C# code?
My original C# code:
public static HtmlDocument RemoveUselessTags(HtmlDocument doc)
{
doc.DocumentNode.Descendants()
.Where(a => a.Name == "script" || a.Name == "a")
.ToList()
.ForEach(a => a.Remove());
return doc;
}
My "translated" VB code:
Public Shared Function RemoveUselessTags(doc As HtmlDocument) As HtmlDocument
doc.DocumentNode.Descendants()
.Where(Function(a) a.Name = "script" OrElse a.Name = "a")
.ToList()
.ForEach(Function(a) a.Remove())
Return doc
End Function
The problem is that you're using Function
, which is for things which return a value. You should be able to use:
ForEach(Sub(a) a.Remove())
See more on this question at Stackoverflow