|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
enum or static classHi,
I have some constants that I would be using to specify some properties. I found it hard to use enums for this purpose and feel more comfortable using a static class that would have static properties returning the constants. What is THE RIGHT WAY to do it? Thnx =?Utf-8?B?bWF2cmlja18xMDE=?= <mavrick***@discussions.microsoft.com>
Show quoteHide quote wrote in news:02C63C14-159C-41A8-89CB-C352B117B6B7@microsoft.com: Right way? It depends.> Hi, > > I have some constants that I would be using to specify some > properties. > > I found it hard to use enums for this purpose and feel more > comfortable using a static class that would have static properties > returning the constants. > > What is THE RIGHT WAY to do it? > > Thnx > If you are talking a "property bag" type setup, having a static class, or perhaps a singleton, works nicely. If they are different for each user, you can use session, or at least cache by session id, etc. If they are truly constants for the app, spinning up a singleton for the application settings is very nice, as it is quite clean. You can then deploy more as needed, with application deployment of course. You can also have your singleton derive from a dictionary, or similar, and spin it up from config files or database at startup. The point? The correct answer depends on the use and scope of the items. -- Show quoteHide quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA Twitter: @gbworld Blog: http://gregorybeamer.spaces.live.com ******************************************* | Think outside the box! | ******************************************* Look at System.Drawing.Color for example. They chose to make it "public
struct Color" and overloaded its != and == operators, and added few methods like FromKnownColor or GetBrightness (instance methods), and all the colors are declared as "public static Color" followed by color name. Here the colors are something that could have been enums, but the developer wanted some functionality to be associated with that data structure also so he chose a class with a lot of static data. I think that if the overloading of operators and public instance methods were not at all required by the developer there, he would have made it into an enum. Just my thoughts about "enum" vs "class with static members". ...ab Show quoteHide quote "mavrick_101" <mavrick***@discussions.microsoft.com> wrote in message news:02C63C14-159C-41A8-89CB-C352B117B6B7@microsoft.com... > Hi, > > I have some constants that I would be using to specify some properties. > > I found it hard to use enums for this purpose and feel more comfortable > using a static class that would have static properties returning the > constants. > > What is THE RIGHT WAY to do it? > > Thnx > chose a class with a lot of static data. I think that if the overloading I meant struct, but class can also be used> of > Just my thoughts about "enum" vs "class with static members". Now bcuz of my misused words up there I hope you dont get confused about class/struct .. classes vs structs :). But before asking here just google a bit and u'll find a lot of clear n easy to understand info. Just in case. Show quoteHide quote "Abubakar" <noem***@nowhere.com> wrote in message news:OMi8hp67JHA.5476@TK2MSFTNGP05.phx.gbl... > Look at System.Drawing.Color for example. They chose to make it "public > struct Color" and overloaded its != and == operators, and added few > methods like FromKnownColor or GetBrightness (instance methods), and all > the colors are declared as "public static Color" followed by color name. > Here the colors are something that could have been enums, but the > developer wanted some functionality to be associated with that data > structure also so he chose a class with a lot of static data. I think that > if the overloading of operators and public instance methods were not at > all required by the developer there, he would have made it into an enum. > > Just my thoughts about "enum" vs "class with static members". > > ..ab > > > "mavrick_101" <mavrick***@discussions.microsoft.com> wrote in message > news:02C63C14-159C-41A8-89CB-C352B117B6B7@microsoft.com... >> Hi, >> >> I have some constants that I would be using to specify some properties. >> >> I found it hard to use enums for this purpose and feel more comfortable >> using a static class that would have static properties returning the >> constants. >> >> What is THE RIGHT WAY to do it? >> >> Thnx >
Other interesting topics
Visual Basic is Dead!
Detailsview updading issue Basic question: returning @@IDENTITY from stored procedure... Document markup language version question PrincipalContext in class constructor Change Scheme From HTTP To HTTPS On PostBack Skinning Question for checkboxes Custom Authentication Return GridView sort to default Compatibility of asp.net 2.0 http modules with 3.5 |
|||||||||||||||||||||||