private
in C# is truly only part of the language specification; in the C# language, as well as in the Visual Basic language or any other sensible .NET language (including CIL, what all the .NET languages compile to) one is prevented from accessing a private
(or protected
, if you're not within a derived class) member in the language. However, just because the language doesn't support publicly accessing private
or protected
members doesn't mean the underlying framework can't provide access to those members.
This is one of those cases where one typically shouldn't be using workarounds like reflection to access or modify private
or protected
members, but the framework allows one to anyway. Generally, you should have a very good reason to access private
or protected
members; one such reason, for example, is implementing a serializer that needs to look at the object's internal state to properly serialize the object. If you're not doing something like that, you should truly look at reimplementing the class you're poking around inside, so that you don't need to use reflection in your program.