Home All Groups Group Topic Archive Search About
Author
24 Feb 2006 7:14 PM
rlrcstr
Really what I want is an enumeration that returns strings rather than
integers.  Since, as far as I know, that's not possible, I thought to create
a class with shared members that return strings.  Kind of like a qualified
constant list so that you can type the name of the class and then get, via
intellisense, a list of the possible values.

I thought that if I created a class with nothing but shared variables, I
wouldn't have toi instantiate it before I used it, since the members were
all shared.  Kind of like using the Math object.  You just use it, don't
declare one first.

However, it's not working.  The compiler keeps complaining that I don't have
an instance.  How do I create a class that acts like a global instance?
Thanks.

Jerry

Author
24 Feb 2006 7:58 PM
Herfried K. Wagner [MVP]
<rlrcstr@newsgroups.nospam> schrieb:
> Really what I want is an enumeration that returns strings rather than
> integers.  Since, as far as I know, that's not possible, I thought to
> create a class with shared members that return strings.  Kind of like a
> qualified constant list so that you can type the name of the class and
> then get, via intellisense, a list of the possible values.
>
> I thought that if I created a class with nothing but shared variables, I
> wouldn't have toi instantiate it before I used it, since the members were
> all shared.  Kind of like using the Math object.  You just use it, don't
> declare one first.

If you are using VS 2005, check out the first source code listing at
<URL:http://dotnet.mvps.org/dotnet/articles/enums/>.

Creating enumerations of items with a certain arbitrary data type
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenums&lang=en>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Feb 2006 7:23 AM
Yuan Ren[MSFT]
Hi Jerry,

Thanks for posting!

Herfried's suggestion is appreciated! Since the enumeration type only
allows the storage of numeric type, there are some other ways to approach
the current demand.

In addition, we can use the custom attributes to be a workaround. The
following article from the CodeProject demonstrates how to use the
StringValueAttribute for the enumeration type in C#:
http://www.codeproject.com/csharp/stringenum.asp

I hope this will be helpful. If you need a VB.NET version, please feel free
to let me know. It's my pleasure to be a future assistance.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
updated on February 14, 2006.  Please complete a re-registration process
by entering the secure code mmpng06 when prompted. Once you have
entered the secure code mmpng06, you will be able to update your profile
and access the partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
Author
2 Mar 2006 1:39 PM
rlrcstr
Interesting stuff..  Thanks.

""Yuan Ren[MSFT]"" <v-y***@microsoft.com> wrote in message
Show quoteHide quote
news:sDyJhD3OGHA.128@TK2MSFTNGXA01.phx.gbl...
> Hi Jerry,
>
> Thanks for posting!
>
> Herfried's suggestion is appreciated! Since the enumeration type only
> allows the storage of numeric type, there are some other ways to approach
> the current demand.
>
> In addition, we can use the custom attributes to be a workaround. The
> following article from the CodeProject demonstrates how to use the
> StringValueAttribute for the enumeration type in C#:
> http://www.codeproject.com/csharp/stringenum.asp
>
> I hope this will be helpful. If you need a VB.NET version, please feel
> free
> to let me know. It's my pleasure to be a future assistance.
>
> Regards,
>
> Yuan Ren [MSFT]
> Microsoft Online Support
> ======================================================
> PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
> updated on February 14, 2006.  Please complete a re-registration process
> by entering the secure code mmpng06 when prompted. Once you have
> entered the secure code mmpng06, you will be able to update your profile
> and access the partner newsgroups.
> ======================================================
> When responding to posts, please "Reply to Group" via your newsreader
> so that others may learn and benefit from this issue.
> ======================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ======================================================
>
Author
3 Mar 2006 2:25 AM
Yuan Ren[MSFT]
Hi Jerry,

You are welcome:)

Yuan Ren [MSFT]
Microsoft Online Support