Organizing c# code into different files

后端 未结 4 1728
礼貌的吻别
礼貌的吻别 2021-01-14 06:23

I\'ve gotten to a point where my main code file is about a thousand lines long and it\'s getting un-manageable; that is, I\'m starting to get confused and not know where to

4条回答
  •  春和景丽
    2021-01-14 06:39

    Yes, but you need to be in the same namespace and declare the class just like you did in the main file, an example:

    file1.cs

    namespace Names
    {
        public partial class Hello
        {
            public void DoSomething() { }
        }
    }
    

    file2.cs

    namespace Names
    {
        public partial class Hello
        {
            public void Go() { DoSomething(); }
        }
    }
    

提交回复
热议问题