473,808 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not quite an enum, not quite a dictionary

I have a list of strings each represented by a number. I want those
string to be constant and put as litle hit as I can on the performance
of my application. The strings are mutualy exclusive, juste like an
Enum. I would use the Enum, but my string contains special caracter
and spaces. I would use a dictionary, but then the string could be
changed at runtime and it would add unnecesary overhead to my
application.

What would be the best solution?
Jan 24 '08 #1
9 1468
On 2008-01-24, ps*******@hotma il.com <ps*******@hotm ail.comwrote:
I have a list of strings each represented by a number. I want those
string to be constant and put as litle hit as I can on the performance
of my application. The strings are mutualy exclusive, juste like an
Enum. I would use the Enum, but my string contains special caracter
and spaces. I would use a dictionary, but then the string could be
changed at runtime and it would add unnecesary overhead to my
application.

What would be the best solution?
Hmmm... Maybe a custom EnumConverter?

http://weblogs.asp.net/mnolton/pages...merations.aspx

--
Tom Shelton
Jan 24 '08 #2
Interesting to say the least. I think it is a litle too complicated
for my project though. It seems to adds a lot of complexity to the
code.

On 24 jan, 14:27, Tom Shelton <tom_shel...@YO UKNOWTHEDRILLco mcast.net>
wrote:
>
Hmmm... Maybe a custom EnumConverter?

http://weblogs.asp.net/mnolton/pages...merations.aspx

--
Tom Shelton
Jan 24 '08 #3
I have a list of strings each represented by a number. I want those
string to be constant and put as litle hit as I can on the performance
of my application. The strings are mutualy exclusive, juste like an
Enum. I would use the Enum, but my string contains special caracter
and spaces. I would use a dictionary, but then the string could be
changed at runtime and it would add unnecesary overhead to my
application.
You could make an enum using underscore instead of space to gain all the
benefits of an enum. As needed, you could do such things as overriding
ToString to replace underscore with space, etc.

Jan 25 '08 #4
<ps*******@hotm ail.comschrieb:
>I have a list of strings each represented by a number. I want those
string to be constant and put as litle hit as I can on the performance
of my application. The strings are mutualy exclusive, juste like an
Enum. I would use the Enum, but my string contains special caracter
and spaces. I would use a dictionary, but then the string could be
changed at runtime and it would add unnecesary overhead to my
application.
Creating enumerations of items with a certain arbitrary data type
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenum s&lang=en>

You could use constants or 'ReadOnly' string fields instead of the
properties.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jan 25 '08 #5
You got in my idea all answers on the first part of your question, however
your question conflicts

The first part
>I have a list of strings each represented by a number. I want those
string to be constant and put as litle hit as I can on the performance
of my application. The strings are mutualy exclusive, juste like an
Enum. I would use the Enum, but my string contains special caracter
and spaces.
The second part
>I would use a dictionary, but then the string could be
changed at runtime and it would add unnecesary overhead to my
application.
For the latter would generics do a fine job.

What is it?

Cor
Jan 25 '08 #6
On 24 jan, 23:43, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
wrote:
You got in my idea all answers on the first part of your question, however
your question conflicts

The first part
I have a list of strings each represented by a number. I want those
string to be constant and put as litle hit as I can on the performance
of my application. The strings are mutualy exclusive, juste like an
Enum. I would use the Enum, but my string contains special caracter
and spaces.

The second part
I would use a dictionary, but then the string could be
changed at runtime and it would add unnecesary overhead to my
application.

For the latter would generics do a fine job.

What is it?

Cor
The string are constant. It's the type of supplier in a financial
application. The problem is, in some flat files, the type are written
in string, but in the database, they have been mapped to an integer
field to save space.

ex:

1 Intermédiaire
2 Personne morale
3 Personne physique
...
etc.

As you can see, the type have space in them and some spécial caracter
i'd rather not have or can't in a enum name. What i would realy liked
would have been an enum where I could have used the space and special
caracter
Jan 25 '08 #7
On 24 jan, 20:28, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrot e:
>
Creating enumerations of items with a certain arbitrary data type
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenum s&lang=en>

You could use constants or 'ReadOnly' string fields instead of the
properties.

--
*M S * Herfried K. Wagner
M V P *<URL:http://dotnet.mvps.org/>
*V B * <URL:http://dotnet.mvps.org/dotnet/faqs/>
Look pretty good I could probably tinker with it. It's probably not as
efficient as an enum, but I doubt I can have both world.
Jan 25 '08 #8
You mean something like this?
http://msdn2.microsoft.com/en-us/lib...ictionary.aspx

Cor
Jan 25 '08 #9
On 25 jan, 13:34, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
wrote:
You mean something like this?http://msdn2.microsoft.com/en-us/lib...ions.specializ...

Cor
No, a standard dictionary would do, I need the key as an integer and
the value as a string.

I believe I'll have to fall back to some form of arbitrary enum like
M. Wagner suggested. It's probably more efficient that using a read
only Dictionary

I'd like to thank everyone for their help. I'll keep you posted on my
progress.
Jan 25 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
4610
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
1
1912
by: Donal McWeeney | last post by:
Just thinking out loud here and looking for feedback in case I missed something... I was to track some additional properties around an enum I have - for example a display name and a description. So I was thinking a building a class EnumDescriptor to store these properties - and make it generic so that it could be used for all enums. I also need to be able to store and manage a collection of these EnumDescriptor objects... for this I...
20
15227
by: John Wood | last post by:
OK here's a random one for you: How do you pronounce enum when you say it? Some say "e-noom", others say "en-um".
31
3624
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1(); Control c = f; An enum value inherits from int but it doesn't get implicitly converted: HorizontalAlignment h = HorizontalAlignment.Center;
15
16669
by: apm | last post by:
Can an enum start empty and be added to on the fly?
34
11210
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a standard enum, so I wanted to know what you experts all thought. Is there a case for standard enums?
4
1728
by: Gary | last post by:
I have a status text on my status bar which simply lists the logged in user name. the code that puts text into this is: stUserName.Text = "Currently logged in user: " + System.Environment.UserName; However our login names here are firstname, surname initial, like so: -
6
2230
by: Zytan | last post by:
I have an enum. I want a struct of data associated with each one. Then, I could use the enum to access the data as needed. In other words, I want the enum to represent more than just a unique integer. I want it to represent a struct. Is there a way to do this nicely? Searching seems to say "no." (Enum.GetValues(myenum).Length is not a constant, apparantly, which is
11
8827
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, is it possible to have spaces in enum values? I have an enum like this: public enum Columns { Italy = 1, OtherCountryUE = 2, OtherCountryOCSE = 3, OtherCountr= 4 } and I'd like to have
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.