Class declared inside of another class in C#

前端 未结 7 1236
庸人自扰
庸人自扰 2021-02-02 06:12

I am working on some legacy code and have come across something that I\'m not sure of. We have a class y that is declared inside of another class x.

7条回答
  •  自闭症患者
    2021-02-02 06:25

    You could still refactor your class y into another file, but use a parial class. The benefit of this is that you still have one class per file and don't have the refactoring hassles of moving the declaration outside of class x.

    e.g. you could have a code file: x.y.cs which would look something like

    partial class X
    {
        class Y
        {
            //implementation goes here
        }
    } 
    

提交回复
热议问题