Skip to content

chore: adding a code example in bc30469 #31799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions docs/visual-basic/misc/bc30469.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,42 @@ You have referenced a non-shared member within your code and failed to supply an

## To correct this error

1. Declare the instance as an object variable.

2. Reference the instance by the variable name.
1. Declare the instance as an object variable.

2. Reference the instance by the variable name.

```vb
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 the instance you've just created to call the function:
firstCustomerAccountNumber = firstCustomer.GetAccountNumber()
Console.WriteLine(firstCustomerAccountNumber)
End Sub
End Module
```

## See also

- [Shared](../language-reference/modifiers/shared.md)