我可以将我的C#类拆分为多个文件吗? [英] Can I split my C# class across multiple files?

查看:60
本文介绍了我可以将我的C#类拆分为多个文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的课:

I have a class that looks like this:

public static class ReferenceData
{

    public static IEnumerable<SelectListItem> GetAnswerType()
    {
        return new[]
            {
                new SelectListItem { Value = "1", Text = "1 answer"  },
                new SelectListItem { Value = "2", Text = "2 answers" },
                new SelectListItem { Value = "3", Text = "3 answers" }
            };
    }

    public static IEnumerable<SelectListItem> GetDatastore()
    {
        return new[]
            {
                new SelectListItem { Value = "DEV", Text = "Development"  },
                new SelectListItem { Value = "DC1", Text = "Production" }
            };
    }
    public static string GetDatastoreText(string datastoreValue)
    {
        return GetDatastore().Single(s => s.Value == datastoreValue).Text;
    }
    public static string GetDatastoreValue(string datastoreText)
    {
        return GetDatastore().Single(s => s.Text == datastoreText).Value;
    }

    // Lots more here
    // Lots more here

}

我上面没有显示更多内容.

There's a lot more that I didn't show above.

当前,所有类信息都在一个文件中.但是,我想将其拆分为多个文件.有什么方法可以将ReferenceData类的内容分布到多个文件中?

Currently all of the class information is in one file. However I would like to split this into multiple files. Is there some way that I can spread the contents of the ReferenceData class across more than one file?

推荐答案

是的,在每个文件的类声明中的类声明中都包括关键字 partial .

Yes, include the keyword partial in the class declaration in every file where you do so.

http://msdn.microsoft.com/en-us/library/wa80x488.aspx

这篇关于我可以将我的C#类拆分为多个文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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