加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net – 一个Roslyn的bug?在非共享成员上,我收到错误,我正在

发布时间:2020-12-17 07:28:29 所属栏目:百科 来源:网络整理
导读:有以下简单的代码: Class A Private value As Integer = 1 Sub Action(Optional param1 As Integer = value) End SubEnd Class Visual Studio抱怨错误BC30369的默认值(值): Cannot refer to an instance member of a class from within a shared method or
有以下简单的代码:

Class A

    Private value As Integer = 1

    Sub Action(Optional param1 As Integer = value)
    End Sub

End Class

Visual Studio抱怨错误BC30369的默认值(值):

Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

对于这种情况,这真的是错误的吗?该方法不共享.

在Visual Studio 2012或2013中,同一情况下的错误是

Constant expression is required.

什么绝对有道理.

解决方法

经过进一步研究后,我认为编译器进行检查的顺序存在问题.

如果我更改代码,使值成员共享,我得到正确的结果:错误BC30059

Constant expression is required.

由于除了常量之外的任何内容都不能置于Optional子句的默认值中,因此检查上面的BC30059(“需要常量表达式”)应该明显比BC30369的检查“更早”(如图所示).

我创建了bug report at Microsoft Connect.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读