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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:16:13+00:00 2026-05-31T18:16:13+00:00

Our app uses a string to house character-values used to indicate enum values. for

  • 0

Our app uses a string to house character-values used to indicate enum values. for ex, the enum for aligning cells in a table:

enum CellAlignment
{
    Left = 1,
    Center = 2,
    Right = 3
}

and the string used to represent alignments for a table of 5 columns: "12312". Is there a snappy way to use LINQ to convert this string into CellAlignment[] cellAlignments?

here’s what I’ve resorted to:

//convert string into character array
char[] cCellAligns = "12312".ToCharArray();

int itemCount = cCellAligns.Count();

int[] iCellAlignments = new int[itemCount];

//loop thru char array to populate corresponding int array
int i;
for (i = 0; i <= itemCount - 1; i++)
    iCellAlignments[i] = Int32.Parse(cCellAligns[i].ToString());

//convert int array to enum array
CellAlignment[] cellAlignments = iCellAlignments.Cast<CellAlignment>().Select(foo => foo).ToArray();

…ive tried this but it said specified cast not valid:

CellAlignment[] cellAlignmentsX = cCellAligns.Cast<CellAlignment>().Select(foo => foo).ToArray();

thank you!

  • 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-05-31T18:16:14+00:00Added an answer on May 31, 2026 at 6:16 pm

    Sure:

    var enumValues = text.Select(c => (CellAlignment)(c - '0'))
                         .ToArray();
    

    That assumes all the values are valid, of course… it uses the fact that you can subtract ‘0’ from any digit character to get the value of that digit, and that you can explicitly convert from int to CellAlignment.

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

Sidebar

Related Questions

Our app uses a component that requires a license file in the directory with
Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some
I'm having a problem at work in that our app which uses WCF for
We have a Spring application that uses Apache DBCP for connection pooling. Our app
We are doing some optimization of our app that heavily uses EWS and one
Our app uses the PHP- aswell as the JS-SDK of Facebook. We are able
our delphi win32 app uses special characters like micro and copyright. we mostly use
Our app uses the send method to call functions on our objects. Unfortunately, some
In our app spring security uses ldap as a provider. i am working on
Our app uses Rails.cache in the controller to cache some items outside the scope

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.