Hi,
Can I have enum contain strings?
Thank you,
Alan 5 1471
No. But if you name them right, you can use myenum.ToString () to get a
string value that might compare to what you want.
"A.M-SG" <al******@newsg roup.nospam> wrote in message
news:uZ******** ******@tk2msftn gp13.phx.gbl... Hi,
Can I have enum contain strings?
Thank you, Alan
Alan,
Afraid not. Integral types only (except char) - sbyte, byte, short, ushort,
int, uint, long and ulong.
All the Best,
Phil.
"A.M-SG" wrote: Hi,
Can I have enum contain strings?
Thank you, Alan
Alan,
As others have mentioned, no, you can not. In this situation, what I
like to do is declare an enumeration, and then apply attributes to the
values of the enumeration (after all, they are static fields) which I
retrieve at runtime to get the information I need.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"A.M-SG" <al******@newsg roup.nospam> wrote in message
news:uZ******** ******@tk2msftn gp13.phx.gbl... Hi,
Can I have enum contain strings?
Thank you, Alan
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:ui******** ******@TK2MSFTN GP09.phx.gbl... Alan,
As others have mentioned, no, you can not. In this situation, what I like to do is declare an enumeration, and then apply attributes to the values of the enumeration (after all, they are static fields) which I retrieve at runtime to get the information I need.
Are you thinking of somethine like:
public enum Goups
{
sCH3,
etc.
}
GroupAttributes ga = new GroupAttributes (etc.)
GroupAttributes [] gaArray = new etc.
gaArray[(int)sCH3] = ga;
In words: (1) make enum (2) use enum to refer to attributes stored in an
array
??????? Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"A.M-SG" <al******@newsg roup.nospam> wrote in message news:uZ******** ******@tk2msftn gp13.phx.gbl... Hi,
Can I have enum contain strings?
Thank you, Alan
apm,
No, I'm thinking something more like this:
public class MyAttribute : Attribute
{
// You can put other stuff in here.
}
public enum Goups
{
[field:MyAttribu te]
sCH3
}
You can then write a generic routine that takes the enumeration value,
as well as the attribute to return, and return it. It works pretty well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"apm" <Co*********@Ad sorptionProcess Modeling.com> wrote in message
news:1QBWe.1175 2$nq.8126@laker ead05... "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:ui******** ******@TK2MSFTN GP09.phx.gbl... Alan,
As others have mentioned, no, you can not. In this situation, what I like to do is declare an enumeration, and then apply attributes to the values of the enumeration (after all, they are static fields) which I retrieve at runtime to get the information I need.
Are you thinking of somethine like:
public enum Goups { sCH3, etc. }
GroupAttributes ga = new GroupAttributes (etc.)
GroupAttributes [] gaArray = new etc.
gaArray[(int)sCH3] = ga;
In words: (1) make enum (2) use enum to refer to attributes stored in an array ??????? Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"A.M-SG" <al******@newsg roup.nospam> wrote in message news:uZ******** ******@tk2msftn gp13.phx.gbl... Hi,
Can I have enum contain strings?
Thank you, Alan
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Russell Shaw |
last post by:
Hi,
gcc-3.4 complains about non-integers in:
enum {IDENTIFIER = "<identifier>", WIDGETDEF = "widgetdef"};
even if i cast the strings to integers.
|
by: guoqi zheng |
last post by:
Trying to declare a enum datatype.
Below works
Public Enum EnumCharSet
IBM037
IBM437
IBM500
End Enum
|
by: Ben Finney |
last post by:
Howdy all,
I've uploaded enum 0.3 to the Cheeseshop.
<URL:http://cheeseshop.python.org/pypi/enum/>
Enumerations are now sequences, iterable (as before) *and* indexable::
>>> from enum import Enum
>>> Weekdays = Enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
|
by: rsennat |
last post by:
Hi,
Converting enum to strings is simple. Just we can use the enum as the i ndex to get the string from an array of strings.
But how do I convert string to enum. Should I need to compare with every string in the array and return the enum when it matches.
Whats the efficient way to do this?
Thanks
rsennat
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |