应在C#中的枚举有自己的文件? [英] Should enums in C# have their own file?

查看:160
本文介绍了应在C#中的枚举有自己的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用枚举类,枚举目前在其自己的文件,这似乎浪费了。

I have a class which uses an enumeration, the enum is currently in its own file which seems wasteful.

什么是枚举普遍的看法放在内它们在消费的文件的名称空间?还是应该枚举真正生活在自己的CS文件?

What is the general opinion on enums being placed within the namespace of a file that they are consumed in? Or should the enum really live in its own cs file?

修改

我要指出,虽然有关的类使用这些枚举,所以做外部呼叫者。换句话说,另一类可以设置这些枚举。因此,他们不会在内部使用的类,否则这个问题是没有道理的。

I should mention that while the class in question uses these enumerations, so does external callers. In other words, another class can set these enumerations. So they are not used internally to the class, otherwise this question would be a no brainer.

推荐答案

我不会说浪费(多少钱一个额外的文件成本?),但它往往是inconventient。通常有一个与该枚举最密切associtated一个班,我把它们放在同一个文件。

I wouldn't say "wasteful" (how much does an extra file cost?), but it is often inconventient. Usually there's one class that's most closely associtated with the enum, and I put them in the same file.

这篇关于应在C#中的枚举有自己的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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