I have some code that builds a string array using data from a form:
string[] var4 = new string[] {
"Issue=" + DropDownListIssue.SelectedItem.ToString(),
"SubIssue=" + DropDownListSubIssue.SelectedItem.ToString(),
"Layout=" + DropDownListLayout.SelectedItem.ToString()
};
This code adds all the elements to the array even if there is no data. For example, say the value of Issue is “Apple,” but the other two dropdownlists are left blank. The resulting var4 would be this:
"Issue=Apple"
"SubIssue="
"Layout="
In this case, I would like var4 to be:
"Issue=Apple"
SubIssue and Layout are not added to the array as they are left blank. If they are filled in, however, then they should be added to the array. Example:
"Issue=Apple"
"SubIssue=Dog"
"Layout=Square"
How can I write this to only add the string when it has a value?
1 Answer