Global Objects

G

Guest

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
 
H

Herfried K. Wagner [MVP]

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>
 
Y

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.
======================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top