为什么这个(翻译后的)VB.NET 代码不起作用?
我转换了一段 C# 代码,但翻译后的代码无效...有人可以帮忙吗?
C#
<table>
<% Html.Repeater<Hobby>("Hobbies", "row", "row-alt", (hobby, css) => { %>
<tr class="<%= css %>">
<td><%= hobby.Title%></td>
</tr>
<% }); %>
</table>
VB
<% Html.Repeater(of Hobby)(Model.Hobbies, "row", "row-alt", Function(hobby, css) Do %>
<tr class="<%= css %>">
<td><%= hobby.Title%></td>
</tr>
<% End Function)%>
I had a piece of C# code converted, but the translated code isn't valid... Can somebody help out?
C#
<table>
<% Html.Repeater<Hobby>("Hobbies", "row", "row-alt", (hobby, css) => { %>
<tr class="<%= css %>">
<td><%= hobby.Title%></td>
</tr>
<% }); %>
</table>
VB
<% Html.Repeater(of Hobby)(Model.Hobbies, "row", "row-alt", Function(hobby, css) Do %>
<tr class="<%= css %>">
<td><%= hobby.Title%></td>
</tr>
<% End Function)%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎正在尝试在 VB.net 中使用语句 lambda。在 Visual Studio 2010 之前,VB.net 不支持这些。该语言的早期版本仅支持表达式 lambda,在这种情况下不起作用。
如果您使用的是 2010,则需要立即删除
Do
位于Function
标头之后。这不是必需的,而是会强制 lambda 成为表达式 lambda 而不是语句 lambda。It looks like you are attempting to use a statement lambda in VB.net. These are not supported in VB.net until Visual Studio 2010. The previous version of the language only supports expression lambdas which don't work in this scenario
If you are using 2010 you need to remove the
Do
immediately following theFunction
header. It's not necessary and will instead force the lambda to be an expression lambda instead of a statement lambda.