Nested Partial Class

后端 未结 2 1850
挽巷
挽巷 2021-02-18 16:07
internal partial class Class1
{
    private class Class2 : ISomething, ISomethingElse
    {
        private class Class3 : ISomething
        {

        }
    }
}
         


        
2条回答
  •  终归单人心
    2021-02-18 16:56

    This article states that it's possible to make nested classes partial even if their parent class is not partial. But then you can't separate them in several files, so I think you need to make Class2 partial too and split just like you would with first-level classes, keeping the partial class hierarchy.

    I really hope that this question is just because of curiosity.

    EDIT: Just tried this - works ok.

    file1.cs

    partial class c1 
    {
        partial class c2 
        {
            class c3 
            {
            }
        }
    }
    

    file2.cs

    partial class c1 
    {
        partial class c2 
        {
        }
    }
    

提交回复
热议问题