C# – Get subclass properties with reflection

When you use reflection to get properties, you can get just the subclass properties by using BindingFlags.DeclaredOnly (this causes it to exclude inherited properties). Here’s an example: Note: Use GetType() if you have an object. Use typeof() if you have a class. The code outputs just the subclass properties (from the Driver subclass): Get base … Read more

C# – Access modifiers

Access modifiers are used to hide class members (methods/properties/fields) from other code. When you define a class/method/property/field, you put an access modifier on it. In C#, there are four main access modifiers: Access modifiers are enforced at compile time. When you try to use a class member that you can’t access, you get the CS0122 … Read more