#638 – Defining and Using a Partial struct

In addition to classes, structs can also be partial, and contain partial methods.  Just like partial classes, a partial struct is one that is split across multiple files.  A partial method in a partial struct is a method that is declared in one portion of the struct and, optionally, implemented in another.

Like a partial method in a class, a partial method in a struct is implicitly private.

    // Dog-1.cs
    public partial struct DogDimensions
        public double Height, Width, TailLength;

        partial void CustomPrintDimensions();


    // Dog-2.cs
    public partial struct DogDimensions
        partial void CustomPrintDimensions()
                string.Format("Dog is {0} in high, {1} in wide, and has a tail that's {2} in long",
                    Height, Width, TailLength));

        public void DumpDimensions()


            DogDimensions dims;
            dims.Height = 14.0;
            dims.Width = 8.0;
            dims.TailLength = 24.0;


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: