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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:09:43+00:00 2026-06-15T04:09:43+00:00

I am trying to enumerate the runtime input to print values of enum variable

  • 0

I am trying to enumerate the runtime input to print values of enum variable in c#.
For example,

class Program
{
   enum Alphabets { a = 1, b, c, d, e, f, g, h }

   public static void Main(String[] args)
   {
       string s = Console.ReadLine();

       foreach(char c in s)
       {
           foreach(int i in Enum.GetValues(typeof(Alphabets)))
              Console.WriteLine(s[i]);
       }

       Console.ReadKey();
   }
}

I stored the user input in String s. I need to display the integer values of the string provided by the user.
The above code show some error like the following:
Index error!
How can i correct this? or provide me a efficient code please..

  • 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-15T04:09:44+00:00Added an answer on June 15, 2026 at 4:09 am

    I think you want something along these lines:

    string line = Console.ReadLine();
    foreach (char c in line)
    {
        string name = c.ToString();
        Alphabets parsed = (Alphabets) Enum.Parse(typeof(Alphabets), name);
        Console.WriteLine((int) parsed);
    }
    

    So this converts each character into a string, and tries to parse it as a member of Alphabets. Each parsed value is then converted into an int just by casting.

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

Sidebar

Related Questions

I'm trying to enumerate some operators, my code line is : enum operations{+=4,-,%,<,>} when
I am trying to enumerate the values in a SearchResultCollection. Everything compiles fine, but
I am trying to make a method to enumerate any enum , by returning
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
trying to figure out why this is happening - I have an input text
I am getting the following error when trying to enumerate users in LDAP(Lightweight Directory
I am trying to use Reflection.Emit to generate a wrapper class in a dynamic
I'm trying to enumerate through all the Controls of a Page, but all I
I'm trying to enumerate all the permissions used by all the installed packages, however
I'm trying to enumerate, in c#, the reports for a user on reporting services.

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.