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 8924899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:32:53+00:00 2026-06-15T07:32:53+00:00

I have been developing for windows mobile and android for sometime. And I’m confused

  • 0

I have been developing for windows mobile and android for sometime. And I’m confused about these two concepts.

Let’s say I want to make decision based on some the user’s device Screen Size. So I’ll expect so predefined values. I could use a switch statement for handling my logic.
But I’m not sure whether I should use Enum of a Static Class for this purpose. Which one is a better approach.
I can do my logic in these two different ways. Which one is the correct approach? I’m confused. And is it possible for me to use String values also? Because currently I’m sticking with classes, I need to update to use all enums. So How about changing my Class to String Enum? Any way. Thanks.

Using Enum

//My predefined values
public enum ScreenSizeEnum
{
    Small, Medium, Large, XLarge,
}
//Handling Logic
private void SetScreenSize(ScreenSizeEnum Screen)
{
    switch (Screen)
    {
        case ScreenSizeEnum.Large:
            //Do Logic
            break;
        case ScreenSizeEnum.Small:
            //Do Logic
            break;
    }
}

Using Class

//My predefined values
public class ScreenSizeClass
{
    public const int Small = 0;
    public const int Medium = 1;
    public const int Large = 2;
    public const int XLarge = 3;
}
//Handling Logic
private void SetScreenSize(int Screen)
{
    switch (Screen)
    {
        case ScreenSizeClass.Large:
            //Do Logic
            break;
        case ScreenSizeClass.Small:
            //Do Logic
            break;
    }
}
  • 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-15T07:32:55+00:00Added an answer on June 15, 2026 at 7:32 am

    From Enumeration Types (C# Programming Guide):

    An enumeration type (also named an enumeration or an enum) provides an
    efficient way to define a set of named integral constants that may be
    assigned to a variable.

    The following are advantages of using an enum instead of a numeric
    type:

    1. You clearly specify for client code which values are valid for the variable.

    2. In Visual Studio, IntelliSense lists the defined values.

    So if you pass enum, it is strongly typed, so you automatically get control over what you can pass into a method.

    ScreenSizeEnum screenSize = ScreenSizeEnum.Medium;
    SetScreenSize(screenSize); 
    

    When using const or static fields you definitely need to check whether the passed int value is taken from the expected diapason.

    int someScreenSizeValue = ...; //anything
    SetScreenSize(someScreenSizeValue); //compiles
    
    private void SetScreenSize(int screenSizeValue)
    {
        switch (screenSizeValue)
        {
            case ScreenSizeClass.Large:
                //Do Logic
                break;
            case ScreenSizeClass.Small:
                //Do Logic
                break;
            default: 
                // something else, what to do??
                break;
        }
    }
    

    Based on comments:

    If it’s necessary to check, whether some int is defined in enum, one can do something like this:

    int somevallue = 0;
    if(Enum.IsDefined(typeof(ScreenSizeEnum), somevallue))
    {
        //it's ok
    }
    

    Or an extension method:

    public static T GetEnumValue<T>(this string value) where T : struct
    {
        Type t = typeof(T);
    
        if (!t.IsEnum)
        {
            throw new Exception("T must be an enum");
        }
        else
        {
            T result;
    
            if (Enum.TryParse<T>(value, out result))
                return result;
            
            return default(T);
        }
    }
    

    which could be used

    int someValue = 1;
    ScreenSizeEnum screenSize = someValue.GetEnumValue<ScreenSizeEnum>();
    

    As for the string (based on OP’s edited question):

    From enum (C# Reference):

    The approved types for an enum are byte, sbyte, short, ushort, int,
    uint, long, or ulong.

    So you cannot have an enum of strings. But you can use names from enums, as ToString method returns the name, not the value of the enum.

    ScreenSizeEnum.Small.ToString(); //Small
    

    So you can have another extension method on strings:

    public static T GetEnumValue<T>(this string value) where T : struct
    {
        Type t = typeof(T);
    
        if (!t.IsEnum)
        {
            throw new Exception("T must be an enum");
        }
        else
        {
            if (Enum.IsDefined(t, value))
                return (T)Enum.Parse(t, value);
            
            return default(T);
        }
    }
    

    So that

    int intScreenSize = (int)ScreenSizeEnum.Small;
    string strScreenSize = ScreenSizeEnum.Small.ToString();
    ScreenSizeEnum intScreenSizeValue = intScreenSize.GetEnumValue<ScreenSizeEnum>(); //ScreenSizeEnum.Small
    ScreenSizeEnum strScreenSizeValue = strScreenSize.GetEnumValue<ScreenSizeEnum>(); //ScreenSizeEnum.Small
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing in Android for approximately two months now. Yesterday, my eclipse
I am developing a windows application in C#. I have been searching for the
I'm a long-time C++ programmer developing on Windows, and have been using Visual Studio
I have been developing my first mobile site with jQuery Mobile and you can
We have an Windows Mobile 6 project that have been up and running for
I have been developing a windows store app, where I need something like Periodically
I have been developing a C# windows form application in XP. It all works
I have been developing my Android App on Linux and Eclipse for a year
I have a question about Symfony2 performance. I have been developing with Symfony2 under
I have a Java project that I've been developing primarily in windows. I have

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.