【问题】
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
【解决过程】
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.参考了:
大概知道含义是,该行代码,不能用在函数或过程之外,
感觉应该是要移动到此处的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
所以,还是不对。
3.最后,搞清楚此处本意是,要在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
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
最后就可以解决此处所有的问题了:
【总结】
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