Reference to a non-shared member requires an object reference
You have referenced a non-shared member within your code and failed to supply an object reference. You cannot use the class name itself to qualify a member that is not shared. The instance must first be declared as an object variable and then referenced by the variable name.
Error ID: BC30469
To correct this error
Declare the instance as an object variable.
Reference the instance by the variable name.
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
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for