组织的C#代码到不同的文件 [英] Organizing c# code into different files

查看:97
本文介绍了组织的C#代码到不同的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了一个点,我的主要代码文件大约一千行代码,它是获得联合国管理;也就是说,我开始感到困惑和不知道在哪里可以找到一些东西。这是良好的评论,但有只是太多的东西。

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 locate some things. It's well-commented but there's just too much stuff.

我真的希望能够组织我的代码放到不同的文件,每一个都有自己的目的。我想获得的所有帮助VS给我,因为我型我编辑这些其他文件。一幅画可以说千言万语:

I'd really like to be able to organize my code into different files, each with its own purpose. I want to get all the help VS gives me as I type when I edit these other files. A picture can say a thousand words:

是什么,我试图做甚至可能吗?

Is what I'm trying to do even possible?

推荐答案

是的,但你需要在同一个命名空间,并声明,就像你在主文件做了类,一个例子:

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(); }
    }
}

这篇关于组织的C#代码到不同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆