© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
74 replies
CoreVisional

❔ Compare Enum Values with submitted value

Hi, how can I compare the submitted value with values in an enum without using switch-case? For example,
public enum Weekends {
  Saturday,
  Sunday
}

[HttpPost]
public async Task<IActionResult> Create([FromForm] Day day)
{
  var weekendvalues = Enum.GetNames(typeof(Weekends));  
  var values = string.Join(", ", weekendvalues); 

  if (day.Day != values) {
    // Do something
  }
  else if () {
    // Some other things
  }
}
public enum Weekends {
  Saturday,
  Sunday
}

[HttpPost]
public async Task<IActionResult> Create([FromForm] Day day)
{
  var weekendvalues = Enum.GetNames(typeof(Weekends));  
  var values = string.Join(", ", weekendvalues); 

  if (day.Day != values) {
    // Do something
  }
  else if () {
    // Some other things
  }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Duplicate enum values serialization problems
C#CC# / help
2y ago
❔ Attributes on a enum value?
C#CC# / help
3y ago
❔ Prevent accepting numeric values as enum
C#CC# / help
3y ago