Using Partial and Controlling Access Properties

When working on large projects with multiple team members or especially large and complex class implementations, it is useful to split the definition of a class across multiple files. We do this using the partial keyword.

Object-relational mapper

Imagine we want to add statements to the Person class automatically generated by a tool like an object-relational mapper that reads schema information from a database. If the class is defined as partial, then we can split the class into an autogenerated code file and a manually edited code file. Let’s write some code that simulates this example:

Step 1: In Person.cs, add the partial keyword, as shown in the following code:

Get hands-on with 1400+ tech skills courses.