I'm trying to add new values input by the user on a separate windows form into the following array:
public class NameValue
{
public string Name;
public string Value;
public NameValue() { Name = null; Value = null; }
public NameValue(string name, string value) { Name = name; Value = value; }
}
public class DefaultSettings
{
public static NameValue[] Sites = new NameValue[]
{
new NameValue("los angeles, CA", "http://losangeles.craigslist.org/"),
};
public static NameValue[] Categories = new NameValue[]
{
new NameValue("all for sale", "sss"),
};
}
How do I add the new values to the array while keeping the values of the old array?
Edit
I tried using Mr. Noren's function:
static void AddValueToSites(NameValue newValue)
{
int size = DefaultSettings.Sites.Length;
NameValue[] newSites = new NameValue[size + 1];
Array.Copy(DefaultSettings.Sites, newSites, size);
newSites[size] = newValue;
DefaultSettings.Sites = newSites;
}
private void button1_Click(object sender, EventArgs e)
{
NameValue newSite = new NameValue("Test, OR", "http://portland.craigslist.org/");
AddValueToSites(newSite);
Close();
}
But that's not working... The class I am getting data from is:
public partial class Location : Office2007Form
{
public Location()
{
InitializeComponent();
}
static void AddValueToSites(NameValue newValue)...
private void button1_Click(object sender, EventArgs e)...
}
List<T>?IList<T>would be a much more appropriate strategy.