O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.3. Modifying the Retrieval through BindingFlags

As it happens, the string class has five properties, only two of which are public. By default, the Get methods retrieve only public instance members—both inherited members and those declared in the class. We can use a BindingFlags enum object to override the default retrieval policy to retrieve both static and nonpublic members or to suppress retrieval of inherited members.

The BindingFlags enumerators provide instructions to the retrieval algorithm as to what members to consider. The default pair of BindingFlags enumerators consists of Public and Instance. If we want to retrieve the nonpublic members as well, we pass in the NonPublic enumerator.[1] The following, however, does not work:

[1] Provided ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required