Publishers of technology books, eBooks, and videos for creative people

Home > Articles

Prerequisites

  • Print
  • + Share This
This chapter is from the book

Partial Types

Microsoft Visual C# 2005 allows the definition of a type to be composed from multiple partial definitions distributed across any number of source code files for the same module. That option is made available via the modifier partial, which can be added to the definition of a class, an interface, or a struct. Therefore, this part of the definition of a class

public partial MyClass
{
      private string myField = null;

      public string MyProperty
      {
            get
            {
                   return this.myField;
            }
      }
}

and this other part

public partial MyClass
{
      public MyClass()
      {
      }

      public void MyMethod()
      {
        this.myField = "Modified by my method.";
      }
}

can together constitute the definition of the type MyClass. This example illustrates just one use for partial types, which is to organize the behavior of a class and its data into separate source code files.

  • + Share This
  • 🔖 Save To Your Account