Yifan
Yifan

Reputation: 376

(VB.Net) Is there a way for one method to access another method's variables?

If I define an array in the scope of a method, is it possible for another method to have access to it? I would make it global, but I only know the bounds of the array at the end of the first method.

Upvotes: 0

Views: 42

Answers (1)

codemonkeyliketab
codemonkeyliketab

Reputation: 320

The only other option is you pass it as a parameter to your 'other method' if you dont want to make it global.

Otherwise I would suggest capturing both the array and its bounds in a class and save that as a global (instance variable) so you know both the array and its bounds when used in another method. You can check to make sure the bounds and the array are valid before attempting to use it to avoid run time errors.

Upvotes: 1

Related Questions