Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>Application Settings Architecture</em></p> <p><a href="http://msdn.microsoft.com/en-us/library/8eyb2ct1.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/8eyb2ct1.aspx</a></p> <p>Ok, an old post, but I remembered it when I came across a similar situation:</p> <p>...</p> <p>If you go to Project / Project Properties (in VS2008 or VS2010). There is a "Settings" tab.</p> <p>If you add a new value....</p> <p>One of the types is called: System.Collections.Specialized.StringCollection</p> <p>Give it a name (I used "FavoriteColors").</p> <p>Set the type (as instructed above).</p> <p>Set the value(s).</p> <p>The "String Collection Editor" says "Enter the strings in the collection (one per line)".</p> <p>I entered:</p> <p>Red</p> <p>Yellow</p> <p>Black</p> <p>White</p> <p>This will add some xml to your app.config file.</p> <pre><code> &lt;setting name="FavoriteColors" serializeAs="Xml"&gt; &lt;value&gt; &lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;string&gt;red&lt;/string&gt; &lt;string&gt;yellow&lt;/string&gt; &lt;string&gt;black&lt;/string&gt; &lt;string&gt;white&lt;/string&gt; &lt;/ArrayOfString&gt; &lt;/value&gt; &lt;/setting&gt; </code></pre> <p>(You'll be better off going through the steps rather than pasting the xml above, because (for conciseness) I did not add all the xml to this post that is generated.</p> <p>You should be able to "get at" the values via code like this:</p> <pre><code>private void ShowMyFavoriteColors() { Properties.Settings.Default.FavoriteColors.Cast&lt;string&gt;().ToList().ForEach(myfavcolor =&gt; { string temp = myfavcolor; }); } </code></pre> <p>Note, the steps above will produce the below C# code (auto code created for you.... it is <strong>not</strong> code you create) but the code looks like this:</p> <pre><code> [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute(@"&lt;?xml version=""1.0"" encoding=""utf-16""?&gt; &lt;ArrayOfString xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""&gt; &lt;string&gt;red&lt;/string&gt; &lt;string&gt;yellow&lt;/string&gt; &lt;string&gt;black&lt;/string&gt; &lt;string&gt;white&lt;/string&gt; &lt;/ArrayOfString&gt;")] public global::System.Collections.Specialized.StringCollection FavoriteColors { get { return ((global::System.Collections.Specialized.StringCollection)(this["FavoriteColors"])); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload