Avoiding Ambiguities with Local Variables

As previously mentioned, fields are at class level contrary to local variables that are at the method/property level. There could be situations in which a local variable has the same name of a field. For example, consider the following code in which two items are named counter: a class level field and a local variable:

image

The code will be correctly compiled; basically no conflict exists between the two counter members because the second one is enclosed within a method and has no external visibility. This also means that the assignment performed within the DoSomething method will not affect the counter private ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.