
C# 7 and .NET Core: Modern Cross-Platform Development

When working on large projects with multiple team members, it is useful to be able to split the definition of a complex class across multiple files. You do this using the partial
keyword.
Imagine we want to add a new method to the Person
class without having to ask another programmer to close the Person.cs
file. If the class is defined as partial
, then we can split it over as many separate files as we like.
In the Person
class, add the partial
keyword, as shown highlighted in the following code:
namespace Packt.CS7
{
public partial class Person
{
In Visual Studio 2017, on the Project menu, go to Add Class... or press Shift + Alt +
C. Enter the name Person2
. We cannot enter Person
because Visual Studio 2017 isn't smart enough to understand what we want to do. Instead, we must now rename the new class to Person
, change the namespace, and add the public partial
keywords, as shown in the following code:
namespace Packt...
Change the font size
Change margin width
Change background colour