Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How would I write blood group enumeration in C#, where

{A+, B+, O+, AB+}

values are possible to write?


Following program doesn't compile......

public enum EnumBloodGroup
{
O+,
A+,
B+,
AB+,
O-
A-,
B-,
AB-,
}
Posted
Updated 2-Jan-18 11:30am

A simple workround would be to have something like

public enum EnumBloodGroup
{
  OPositive,
  APositive
  ......
  ......
  ONegative
  ........
}


However, that is not very satisfactory. I have seen this exact same problem described somewhere and am off to look for it.

If I find it before someone else posts a satisfactory answer I will come back.
 
Share this answer
 
Take a look at this[^] article.

So in your instance, instead of ice-cream if you must :) , you could have
public enum EnumBloodGroup
{
  [
  Description("O+")
  ]
  OPos,
  [
  Description("B+")
  ]
  BPos,
  .....
  .....
}


Then use the StringValueOf() and EnumValueOf() methods from the article to get the appropriate values.
 
Share this answer
 
Solution: 3
Hey look you can try this way ....
I Have Already Working on it...
public enum Blood
   {
       [Display(Name = "O+")]
       OPositive,
        [Display(Name = "A+")]
       APositive,
        [Display(Name = "B+")]
       BPositive,
        [Display(Name = "AB+")]
       ABPositive,
        [Display(Name = "AB-")]
       ABNegative,
        [Display(Name = "A-")]
       ANegative,
        [Display(Name = "B-")]
       BNegative,
        [Display(Name = "O-")]
       ONegative

   }
 
Share this answer
 
Comments
Dave Kreskowiak 2-Jan-18 19:25pm    
Wow. You're only SEVEN YEARS too late to the discussion.
Mohammad Touhidul Islam 17-Jan-18 17:09pm    
Um new in Here :)
Mohammad Touhidul Islam 17-Jan-18 17:08pm    
Yes I'm new here :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900