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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:32:30+00:00 2026-05-28T06:32:30+00:00

I would like to evaluate a dynamic string value within a switch statement in

  • 0

I would like to evaluate a dynamic string value within a switch statement in C#.

For example:

int i = 0;
foreach (Item item in _Items)
{
    foreach (Field theField in doc.Form.Fields)
    {
        switch (theField.Name)
        {
            case "Num" + i++.ToString(): // Dynamic Evaluation?
                theField.Value = string.Empty;
                break;
        }
    }
}

I have 20 or so fields named Num1, Num2, etc. If I can do this all in one statement/block, I’d prefer to do so.

But the compiler complains that the case statements need to be constant values. Is there a way to use dynamic variables in the case statement so I can avoid repeating code?

I just thought I’d mention, the purpose of this method is to populate the fields in PDF form, with naming conventions which I can not control. There are 20 rows of fields, with names like "Num1" – "Num20". This is why string concatenation would be helpful in my scenario.

  • 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-28T06:32:31+00:00Added an answer on May 28, 2026 at 6:32 am

    No. This is simply part of the language. If the values aren’t constants, you’ll have to use if/else if or a similar solution. (If we knew more details about what you were trying to achieve, we may be able to give more details of the solution.)

    Fundamentally, I’d question a design which has a naming convention for the fields like this – it sounds like really you should have a collection to start with, which is considerably easier to work with.

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

Sidebar

Related Questions

I would like to know how to evaluate a string representation of an equation
I would like to evaluate .NET as a development platform for a desktop application.
I have an array with 16 elements. I would like to evaluate these to
I would like to visually evaluate web pages response time for several Internet connections
I would like to test a string containing a path to a file for
I would like to evaluate an environment variable and set the result to a
I would like to evaluate JPA on an existing project. The database model and
When you push submit it would seem like it should evaluate the header in
I would like to evaluate my threading options for a Visual C++ 2010 (non-managed)
We would like to evaluate whether the SVN protocol works better for our team

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.