473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 1454
On 2008-01-24, ps*******@hotmail.com <ps*******@hotmail.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...@YOUKNOWTHEDRILLcomcast.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*******@hotmail.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=anytypeenums&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.atwrote:
>
Creating enumerations of items with a certain arbitrary data type
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenums&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
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
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....
20
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
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();...
15
by: apm | last post by:
Can an enum start empty and be added to on the fly?
34
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...
4
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: " +...
6
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...
11
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.