locked
class level variable RRS feed

  • Question

  • Public Class BindingSource

        Dim dsAppNames As New DataSet
    public dsAppNames As New DataSet

    end class


    I declared two  datasets  with one dim  and public , are these delaration are same
    these works like same,,

    how they works

    adil
    Thursday, July 10, 2008 11:09 AM

Answers

  • The datasets are the same and they work the same way but their scope is different.  If you were to create a new instance of your class and tried to use these two members the one declared Public would be available but the Dim dataset -- which is Private in scope -- would not be visible.  Private variables and members are only visible from within the class itself.

    Now...  you have given these variables the same name and this is not valid -- so this code would not compile or would definitely fail at runtime.  Remember that the scope keywords are not part of the actual object definition (which I think is what you mean when you ask if they are the same) rather they describe the range of visibility that the member has to other classes.

    Also, I'd be careful creating classes that are identical in name to existing .NET classes.  If you have to do it then be sure to use clear namespacing to differentiate the two.
    Thursday, July 10, 2008 11:54 AM