...

/

Using Partial and Controlling Access Properties

Using Partial and Controlling Access Properties

Learn about splitting classes and data access.

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:

Press + to interact
public partial class Person

Step 2: In the PacktLibraryNetStandard2 project/folder, add a new class ...