Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# App.Config with array or list like data

Tags:

How to have array or list like information in app.config? I want user to be able to put as many IPs as possible (or as needed). My program would just take whatever specified in app.config. How to do this?

<?xml version="1.0" encoding="utf-8" ?> <configuration>   <appSettings>     <add key="ip" value="x" />     <add key="ip" value="y" />     <add key="ip" value="z" />     </appSettings> </configuration>    public string ip = ConfigurationManager.AppSettings["ip"]; 
like image 410
John Ryann Avatar asked May 06 '14 15:05

John Ryann


Video Answer


1 Answers

The easiest way would be a comma separated list in your App.config file. Of course you can write your own configuration section, but what is the point of doing that if it is just an array of strings, keep it simple.

<configuration>   <appSettings>     <add key="ips" value="z,x,d,e" />   </appSettings> </configuration>  public string[] ipArray = ConfigurationManager.AppSettings["ips"].Split(','); 
like image 123
milagvoniduak Avatar answered Sep 22 '22 14:09

milagvoniduak