0

I am not posting any code, I just need some information . Please. I am new to this kind of architecture where different classes are made and they are consumed. How can I make a class which holds the enums or regular expressions constants and stuff. Show I be making a class where I will have to write these enums making them as global. I have some code which i found on google.

// Correct
public enum Color
{
Red,
Green,
Blue,
Yellow,
Magenta,
Cyan
}
// Exception
[Flags]
public enum Dockings
{
None = 0,
Top = 1,
Right = 2,
Bottom = 4,
Left = 8
}

Is this the way I should keep enums in the other class.?

user2998990
  • 970
  • 5
  • 18
  • 36
  • 1
    An `enum` type is a type all by itself. Why would you want to put it in any other class? And if you want to do it, do you have a _specific_ question about how to do that? Please see http://stackoverflow.com/help/how-to-ask for ways to present your question in a way that fits the StackOverflow paradigm. – Peter Duniho Dec 11 '14 at 05:40
  • @PeterDuniho : I need to declare these types and all in classes and use them through out the application. This is exactly what i mean. – user2998990 Dec 11 '14 at 05:42
  • 1
    I think the question is where to store globally required data. You can create a static class to store Enums. Put this class in an assembly that you will then reference from all projects that require it. – Joe Niland Dec 11 '14 at 05:44
  • @JoeNiland : Exactly this is what I want. Thanks. Can you share any link which guides me how to make such classes for enus, regex and etc. – user2998990 Dec 11 '14 at 05:45
  • @user2998990: you can declare an `enum` type regardless. It doesn't need a containing type, can be used "through out the application" without one, and in fact having one only makes using them _more_ difficult and _less_ convenient. It is a big mistake to declare types simply for the purpose of containing other types. Do you simply want your `enum` types (and others) to be in a different _namespace_ from the rest of your code? That would make a lot more sense than what you are asking to do here. – Peter Duniho Dec 11 '14 at 08:59

1 Answers1

1

You can create a static class to store Enums, etc. Put this class in an assembly that you will then reference from all projects that require it.

The answer C# Global Variables provides quite a bit of detail on what you want to achieve.

Community
  • 1
  • 1
Joe Niland
  • 885
  • 1
  • 14
  • 31