Global Objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    #1

    Global Objects

    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


  • Herfried K. Wagner [MVP]

    #2
    Re: Global Objects

    <rlrcstr@newsgr oups.nospam> schrieb:[color=blue]
    > 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.[/color]

    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=anytypeenum s&lang=en>

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

    Comment

    • Yuan Ren[MSFT]

      #3
      RE: Global Objects

      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
      StringValueAttr ibute for the enumeration type in C#:


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

      Comment

      • Guest's Avatar

        #4
        Re: Global Objects

        Interesting stuff.. Thanks.

        ""Yuan Ren[MSFT]"" <v-yren@microsoft. com> wrote in message
        news:sDyJhD3OGH A.128@TK2MSFTNG XA01.phx.gbl...[color=blue]
        > 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
        > StringValueAttr ibute 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.
        > =============== =============== =============== =========
        >[/color]


        Comment

        Working...