Question

I have follwing in app.config file:

<appSettings>
<add key="Name" value="Office"/>
... 

<add key="Name" value="HotSpot"/>

...

<add key="Name" value="Home"/>
</appSettings>

I tried

ConfigurationManager.AppSettings["Name"]

But it only gives me one Value? How can i get list of all values? I am using c# 3.5. Is there lambda expression or something i can use to get that?

Was it helpful?

Solution

You can only use one key per value, so this approach will not work.

There are two alternate approaches I can think of:

  1. Use a single key with a delimiter, and retrieve with ConfigurationManager.AppSettings["Name"].Split(new [] { "," });.

    <add key="Name" value="Office,Hotspot,Home" />

  2. Use a custom section to create a section that can contain your array of strings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top