How can I append strings to an array if a certain checkbox is true?
//Create an array to hold the values.
string[] charArray;
if (abc.Checked == true)
{
//append lowercase abc
}
if (a_b_c.Checked == true)
{
//append uppercase abc
}
if (numbers.Checked == true)
{
//append numbers
}
if (symbols.Checked == true)
{
//append symbols
}
You typically don’t want to try appending to an array in .NET. It can be done, but it’s expensive. In this case, you want to use a StringBuilder
Example:
When you’re done, you can get the string by calling
sb.ToString(), or get the characters by callingsb.CopyTo().Naming an array of strings “charArray” is very confusing.
Or are you trying to append strings, not append characters to a string? You want to use a
List<string>for that, rather than astring[].Example: