Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Enum Member

Enum Member

Scheduled Pinned Locked Moved C#
help
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DIPAK EMSYS
    wrote on last edited by
    #1

    hi guys. Any one has idea about how can we give enum member like A+,B+...

    public enum Color
    {
    Any,
    D+,
    D,
    D-,
    E+
    };

    I tried creating above enum but bad luck its giving error saying } expected.

    dipak

    OriginalGriffO realJSOPR P P 4 Replies Last reply
    0
    • D DIPAK EMSYS

      hi guys. Any one has idea about how can we give enum member like A+,B+...

      public enum Color
      {
      Any,
      D+,
      D,
      D-,
      E+
      };

      I tried creating above enum but bad luck its giving error saying } expected.

      dipak

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      You can't. Enum members follow the normal rules for names - same as methods, properties, fields and namespaces. All you can do is use the word "Plus" or "Minus" instead.

      You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      D 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        You can't. Enum members follow the normal rules for names - same as methods, properties, fields and namespaces. All you can do is use the word "Plus" or "Minus" instead.

        You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

        D Offline
        D Offline
        DIPAK EMSYS
        wrote on last edited by
        #3

        Does it mean that ther is no way to make such member in enum?

        dipak

        OriginalGriffO 1 Reply Last reply
        0
        • D DIPAK EMSYS

          Does it mean that ther is no way to make such member in enum?

          dipak

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Yes. In C#, all identfiers (methods, properties, fields, and namespaces) must adhere to the following rules: The name can contain letters, digits, and the underscore character (_). The first character of the name must be a letter. The underscore is also a legal first character, but its use is not recommended at the beginning of a name. An underscore is often used with special commands, and it's sometimes hard to read. Case matters (that is, upper- and lowercase letters). C# is case-sensitive; thus, the names count and Count refer to two different variables. C# keywords can't be used as variable names. Recall that a keyword is a word that is part of the C# language. The characters '+', '-', '(' ')', '=', ',', ';' and many others cannot be used in the name of any identifier. So, no. You can't do it. At all. Ever.

          You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • D DIPAK EMSYS

            hi guys. Any one has idea about how can we give enum member like A+,B+...

            public enum Color
            {
            Any,
            D+,
            D,
            D-,
            E+
            };

            I tried creating above enum but bad luck its giving error saying } expected.

            dipak

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            You can only use underscores and alphnumeric characters in enum ordinal names. You also can't start the name with a digit.

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            1 Reply Last reply
            0
            • D DIPAK EMSYS

              hi guys. Any one has idea about how can we give enum member like A+,B+...

              public enum Color
              {
              Any,
              D+,
              D,
              D-,
              E+
              };

              I tried creating above enum but bad luck its giving error saying } expected.

              dipak

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Add a Description attribute, and use reflection to extract the description from that e.g

              [Description("D+")]
              DPlus

              There are numerous samples showing how to do this.

              "WPF has many lovers. It's a veritable porn star!" - Josh Smith

              As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

              My blog | My articles | MoXAML PowerToys | Onyx

              D P 2 Replies Last reply
              0
              • P Pete OHanlon

                Add a Description attribute, and use reflection to extract the description from that e.g

                [Description("D+")]
                DPlus

                There are numerous samples showing how to do this.

                "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                My blog | My articles | MoXAML PowerToys | Onyx

                D Offline
                D Offline
                DIPAK EMSYS
                wrote on last edited by
                #7

                thankyou so much ....all guys..

                dipak

                1 Reply Last reply
                0
                • P Pete OHanlon

                  Add a Description attribute, and use reflection to extract the description from that e.g

                  [Description("D+")]
                  DPlus

                  There are numerous samples showing how to do this.

                  "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                  As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                  My blog | My articles | MoXAML PowerToys | Onyx

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  That's what I would have said too. :thumbsup:

                  1 Reply Last reply
                  0
                  • D DIPAK EMSYS

                    hi guys. Any one has idea about how can we give enum member like A+,B+...

                    public enum Color
                    {
                    Any,
                    D+,
                    D,
                    D-,
                    E+
                    };

                    I tried creating above enum but bad luck its giving error saying } expected.

                    dipak

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    As Pete said, use a System.ComponentModel.DescriptionAttribute. See also my Enum Utilities[^] for ways to work with them more easily.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups