Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8681539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:32:16+00:00 2026-06-12T21:32:16+00:00

I have this enum: public enum ContentKey { Menu = 0, Article = 1,

  • 0

I have this enum:

public enum ContentKey {
    Menu = 0,
    Article = 1,
    FavoritesList = 2
};

This action method:

public ActionResult Edit(string pk, string rk, int row = 0) {
    try {
        var content = _contentService.Get(pk, rk);

The following class Content which is based on the TableServiceEntity. Note that TableServiceEntity is common to all my data classes.

public class Content : TableServiceEntity 
{

public abstract class TableServiceEntity
{
    protected TableServiceEntity();
    protected TableServiceEntity(string partitionKey, string rowKey);
    public virtual string PartitionKey { get; set; }

Is there a way I can check the value of pk matches one of the enum values? What I am not sure about is how I can check this. I assume I need to have the check in the Content class but I am not sure how to override the virtual string and throw an exception when there’s no match.

Update: If possible I would like to do this in the Content class get set but I am not sure how to add a get set to this class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:32:17+00:00Added an answer on June 12, 2026 at 9:32 pm

    You can use Enum.IsDefined to see if a string matches an Enum value:

    public enum ContentKey
    {
        Menu = 0,
        Article = 1,
        FavoritesList = 2
    }
    
    static bool Check(string pk)
    {
        return Enum.IsDefined(typeof(ContentKey), pk);
    }
    
    static void Main(string[] args)
    {
        Console.WriteLine(Check("Menu"));
        Console.WriteLine(Check("Foo"));
    }
    

    You can also define a setter that does not set the backing field unless the new value is defined the enum:

    class Foo
    {
        private string pk;
    
        public string PK
        {
            get
            {
                return this.pk;
            }
            set
            {
                if(Enum.IsDefined(typeof(ContentKey), value))
                {
                    this.pk = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
    }
    

    This is a non-automatic property where you define the backing field yourself. The new value is accessible via the value keyword.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class Variables public class Variables { public enum DataType { INT,
I have this Singleton: public enum Elvis { INSTANCE; private int age; public int
I have enum like this public enum Sizes { Normal(232), Large(455); private final int
I have this enum: public enum IndexType : int { /// <summary> /// The
I have this filetypeenum: public enum FileType : int { jpeg = 0, png
So I have something like this public enum DataType { RECORD_TYPE(0), ... private String
Suppose I have this enum: public enum TestEnum { EXAMPLE, FURTHER_EXAMPLE, LAST_EXAMPLE } With
I have this enumeration: public enum Translation { English=1, Russian, French, German } I
I have this enumeration: public enum SymbolPair { AUDJPY = 0, AUDNZD, AUDUSD, CADJPY,
I have enum like this: public enum ObectTypes { TypeOne, TypeTwo, TypeThree, ... TypeTwenty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.