通过


对非共享成员的引用需要对象引用

你引用了代码内的非共享成员,且未能应用对象引用。 类名本身不能用于限定非共享的成员。 必须先将实例声明为对象变量,然后由变量名称引用。

错误 ID: BC30469

更正此错误

  1. 将实例声明为对象变量。

  2. 用变量名称引用实例。

Imports System

Namespace Ecommerce
    Public Class Customer
        Private Property AccountNumber As Integer

        Public Sub New (accountNumber As Integer)
            AccountNumber = accountNumber
        End Sub

        Public Function GetAccountNumber ()
            return AccountNumber + accountNumber
        End Function
    End Class
End Namespace

Module Program
Sub Main(args As String())
        ' Declaring the instance as an object variable:
        Dim firstCustomer As New Ecommerce.Customer(1)
        Dim firstCustomerAccountNumber As Integer

        ' You must not use Ecommerce.Customer.GetAccountNumber() because you
        ' cannot access non-shared Function 'GetAccountNumber' in shared context.
        ' Otherwise, use the instance you've just created to call the function:
        firstCustomerAccountNumber = firstCustomer.GetAccountNumber()
        Console.WriteLine(firstCustomerAccountNumber)
    End Sub
End Module

请参阅