Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:29:32+00:00 2026-06-17T13:29:32+00:00

I was reading the MSDN article on the Partial keyword, and this part caught

  • 0

I was reading the MSDN article on the Partial keyword, and this part caught my eye:

The partial keyword indicates that other parts of the class, struct,
or interface can be defined in the namespace. All the parts must use
the partial keyword. All the parts must be available at compile time
to form the final type. All the parts must have the same
accessibility, such as public, private, and so on.

[…]

All the parts that specify a base class must agree, but parts that
omit a base class still inherit the base type. Parts can specify
different base interfaces
, and the final type implements all the
interfaces listed by all the partial declarations. Any class, struct,
or interface members declared in a partial definition are available to
all the other parts. The final type is the combination of all the
parts at compile time.

I had two questions regarding this concept:

  • Firstly, it seems that this is a way to bypass the lack of multiple inheritance in C# (aside from interfaces, of course). Are there any repercussions to doing so, aside from normal multiple inheritance issues, such as the Diamond Problem? Basically, just because I can, does it mean I should?

  • Secondly, when exactly should I split up files? Just by reading this, it feels like I should be able to declare a nested class in its own file, and partial it together with the containing class, and thereby improve readability. Is this the point of Partial, or should it only be used as described in the above article?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:29:33+00:00Added an answer on June 17, 2026 at 1:29 pm

    Firstly, it seems that this is a way to bypass the lack of multiple inheritance in C# (aside from interfaces, of course). Are there any repercussions to doing so, aside from normal multiple inheritance issues, such as the Diamond Problem? Basically, just because I can, does it mean I should?

    It doesn’t do multiple inheritance. It’s actually way more evil, since it exposes private variables — but at the same time it doesn’t introduce diamonds. Try the following code to see what I mean:

    public class Test0
    {
        protected int bar;
    
        public void Unexpected() { Console.WriteLine("3. {0}", bar); }
    }
    
    public partial class Test1
    {
        private int foo;
    
        public void Foo() { Console.WriteLine("1. {0}", foo); bar = 1; }
    }
    
    public partial class Test1 : Test0
    {
        public void Bar() { Console.WriteLine("2. {0}", foo); foo = 1; }
    }
    
    class Driver
    {
        public static void Main()
        {
            var t1 = new Test1();
            t1.Bar();
            t1.Foo();
            t1.Unexpected();
            Console.ReadLine();
        }
    } 
    

    In other words, you should be very careful with variables.

    Secondly, when exactly should I split up files? Just by reading this, it feels like I should be able to declare a nested class in its own file, and partial it together with the containing class, and thereby improve readability. Is this the point of Partial, or should it only be used as described in the above article?

    Code generation is a well known example. I personally use partial classes a lot when dealing with the Facade pattern (which is very useful when creating WCF/SOAP services). In most cases I try to avoid it for the above reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading through this MSDN article http://msdn.microsoft.com/en-us/library/dd460648.aspx I'm seeing a claim that MEF doesn't have
So , I've been reading this article: http://msdn.microsoft.com/en-us/library/aa290051%28VS.71%29.aspx And I would like to define
Reading this MSDN article titled Working with ObjectSet (Entity Framework) It shows two examples
I was reading this MSDN article about the usage of properties and methods in
I was reading this MSDN article which deals with creating a .NET managed wrapper
I was reading this article on MSDN Managing Heap Memory in Win32 And in
I saw this article pop-up in my MSDN RSS feed, and after reading through
I was reading custom serialization article on msdn: http://msdn.microsoft.com/en-us/library/ty01x675%28VS.80%29.aspx It mentions that there are
After reading Jon Skeet article , and this article from msdn , I still
I've just been reading the article on MSDN about remote validation. This is great,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.