【问题标题】:In VS/VB, system.windows.forms.control is overiding microsoft.vb.strings module, has anyone had this issue before?在 VS/VB 中,system.windows.forms.control 覆盖了 microsoft.vb.strings 模块,以前有人遇到过这个问题吗?
【发布时间】:2019-03-22 11:28:49
【问题描述】:

我突然在 Visual Studio/VB 中遇到错误,其中 system.windows.forms.control 覆盖了 microsoft.vb.strings 模块,因此昨天还不错的代码现在抛出了错误。

dim cat as string="herd of cats"

dim slice as string=Left(cat,4)

在 Left 上抛出错误,“Public Overloads Property Left As Integer”没有参数,并且它的返回类型不能被索引。”

同时,

dim cat as string="herd of cats"

dim slice as string=strings.Left(cat,4)

没问题。我认为由于某种原因它被 system.windows.forms.control.left 属性超载,我不知道如何修复它或它为什么会发生。我完全卸载并重新安装了 Visual Studio,重新安装了 .net 框架以尝试解决问题,但它仍然存在于新的空白程序中。有什么建议吗?

【问题讨论】:

    标签: vb.net visual-studio


    【解决方案1】:

    Left 不明确;它存在于 String 类和 Form 类中,因为代码(可能)在 Form 中,然后“最本地”Left 获胜。

    Left 本身是 VB6 的保留,您不应该真正使用它(您看到的行为是 documented in the remarks)。

    切换到:

    dim slice as string = cat.Substring(0, 4)
    

    【讨论】:

    • 谢谢,在看到您提到“表单”时,我记得我已将有问题的代码从模块移到表单类中。也很高兴知道“左”被贬低了。我不知道。
    • 不应该是Dim slice As String = If(String.IsNullOrEmpty(cat), String.Empty, cat.Substring(0, Math.Min(cat.Length, 4)))来模拟Left函数吗?
    猜你喜欢
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多