最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】VB.Net中提示:statement cannot appear outside of a method body multiline lambda,using must end with a matching End using,character is not valid

VB.Net crifan 4525浏览 0评论

【问题】

VB.Net中,写了几行代码:

Public Class Form1

    using System.Text.RegularExpressions;


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub
End Class

结果提示错误:

statement cannot appear outside of a method body multiline lambda

statement cannot appear outside of a method body multiline lambda

【解决过程】

1.把using移动到class之外:

using System.Text.RegularExpressions;

Public Class Form1




    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub
End Class

结果问题依旧。

2.参考了:

10. Parameters to Procedures

大概知道含义是,该行代码,不能用在函数或过程之外,

感觉应该是要移动到此处的Form1_Load内。

结果把代码变为:

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        using System.Text.RegularExpressions;


    End Sub
End Class

却又出现错误:

using must end with a matching End using

using must end with a matching End using

所以,还是不对。

3.最后,搞清楚此处本意是,要在VB.Net导入正则表达式的类。

然后参考了:

正则表达式在VB.NET中的应用

改为Imports:

Imports System.Text.RegularExpressions;

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub
End Class

然后又提示:

character is not valid

character is not valid

4.然后再把最后的分号去掉:

Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub
End Class

最后就可以解决此处所有的问题了:

imports all ok

 

【总结】

VB.Net中:

  • 正则表达式的类是System.Text.RegularExpressions
  • 导入类是用Imports,最后不要加分号:
    • Imports System.Text.RegularExpressions
  • 写普通语句时,不能单独写在函数或过程之外;

转载请注明:在路上 » 【已解决】VB.Net中提示:statement cannot appear outside of a method body multiline lambda,using must end with a matching End using,character is not valid

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.186 seconds, using 21.94MB memory