右 (S,2) 与 Strings.Right(S,2)

Right(S,2) vs Strings.Right(S,2)

使用VB dot net & Visual Studio 2010,我有一个字符串,我想抓取最右边的两个字符。所以我转到 Right() 函数,它将 完全 那样做。但是在我工作的项目中,无法识别,所以我尽职尽责地在表格顶部插入

Imports Microsoft.VisualBasic

但这还不够...我必须使用Strings.Right(S,2)以避免错误。我知道我有其他项目只使用前面没有 Strings.Right(),但我不确定在那些避免需要额外限定符的设置中有什么不同。

可以更改哪些内容才能使 Right(S,2) 在此项目中正常工作?

编辑:我在没有 Strings. 限定符的情况下遇到的错误是

'Public ReadOnly Property Right as Integer' has no parameters and its return type cannot be indexed.

当我开始输入时 "Right" 的 Intellisense 说:

Gets the distance, in pixels, between the right edge of the control and the left edge of its container's client area

-- 这显然与字符串操作无关。

Right 函数在 Microsoft.VisualBasic.Strings 中定义。有可能您在 Windows Forms 项目中的 Form class 中收到此错误,当您简单地键入 Right(S,2) 时,编译器认为您正在调用正确的 属性 的形式 class。我相信您的选择是将代码移动到表单 class 之外的某个位置,或者使用 Strings.Right.

限定调用

在您的表单 class 中简单地导入 Microsoft.VisualBasic.Strings 将无济于事,因为对 Right 的引用仍然是模棱两可的。