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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:56:08+00:00 2026-06-09T01:56:08+00:00

I have config values as shown below add key=Screen1 value =Admin add key=Screen2 value

  • 0

I have config values as shown below

add key="Screen1" value ="Admin"
add key="Screen2" value ="Log"

In future new screens will get added. In C#, I need to create an array of string with these screen names. How can we do this (keeping in mind that the code need to work even if we add new screens)?

Note 1: I am looking for an approach that does not use custom configuration.

Note 2: I will have maximum of 10 config items with the name starting as “Screen”. But I will have 10,000 other config items.

REFERENCE

  1. Better code/ Pattern for checking existence of value
  2. Generic method for reading config sections
  3. Generating numbers list in C#
  4. Detecting sequence of at least 3 sequential numbers from a given list
  5. Does LINQ cache computed values?
  6. Is there an easy method to combine two relative paths in C#?
  • 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-09T01:56:10+00:00Added an answer on June 9, 2026 at 1:56 am
    ConfigurationManager.AppSettings.AllKeys
        .Where( key => key.StartsWith( "Screen" ) )
        .Select( key => ConfigurationManager.AppSettings[key] )
    

    If you have a lot of settings (say, 10K, like you specified in the comments), you may benefit from the fact that the AppSettings collection is optimized for lookup by key. For this, you’ll have to repeatedly try “Screen1”, “Screen2”, “Screen3”, etc., and stop when no value is found:

    Enumerable.Range( 1, int.MaxValue )
        .Select( i => ConfigurationManager.AppSettings[ "Screen" + i ] )
        .TakeWhile( value => value != null )
    

    This approach, however, is exactly the kind of “premature optimization” that Mr. Knuth warned us about. The config file simply shouldn’t contain that many settings, period.

    Another disadvantage: keep in mind that this approach assumes that there are no gaps in the numbering of “Screen*” settings. That is, if you have “Screen1”, “Screen2”, and “Screen4”, it will not pickup the last one. If you’re planning on having a lot of these settings, it will become very inconvenient to “shift” all the numbers every time you add or remove a setting.

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

Sidebar

Related Questions

Hi I have add the provider in my web config as below: <add name=MvcSiteMapProvider
i have created xml file with the code shown below, XElement xml = new
I have web.config entries as shown below. This is for controlling access of users
I have configuration values saved in an app.config . I want to create a
I have a test project, with an App.config that sets up default values for
I have an XML input as shown below: <?xml version=1.0 encoding=utf-8?> <Content> <section name=FileID/>
I have config.php with this... $dbhost = localhost; I want to be able to
I do NOT have config.active_record.whitelist_attributes = true in application config. And I have attr_protected()
In application.rb, I have config.autoload_paths += %W(#{config.root}/lib So when I modify a class under
I have a config file like package com.mypackage.referencedata.config; @Configuration @ComponentScan (com.mypackage.referencedata.*) public class ReferenceDataConfig

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.