I am a novice at C#, yet I know I should be able to figure this out. My searching skills have not given me a direct answer either.
I have two application settings that are stored in string arrays (they have been split from a , separated list).
Ultimately I want to run one chunk of code, conditional upon both settings.
Conditions are:
- If settings exist in array 1 (domattributes), run the code on each setting value.
- If settings also exist in array 2 (intlattributes), run the code on each setting value contained in either array 1 or array
- Below is how I have tried to do it using an if/else statement to build out the string array, but it doesn't work.
I get the error
The name 'attributeIds' does not exist in the current context
I am assuming it is because the string array is actually built in the if/else statement, and is probably in a different scope from the foreach method that is trying to use it. Any help would be appreciated. Here's the code:
if (!string.IsNullOrEmpty(DomAttributesSetting))
{
if (!string.IsNullOrEmpty(IntlAttributesSetting))
{
string[] domattributeIds = DomAttributesSetting.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string[] intlattributeIds = IntlAttributesSetting.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string[] attributeIds = new string[domattributeIds.Length + intlattributeIds.Length];
Array.Copy(domattributeIds, attributeIds, domattributeIds.Length);
Array.Copy(intlattributeIds, 0, attributeIds, domattributeIds.Length, intlattributeIds.Length);
}
else
{
string[] attributeIds = DomAttributesSetting.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
foreach (string attributeId in attributeIds)
{
PersonAttribute personAttribute = (PersonAttribute)person.Attributes.FindByID(int.Parse(attributeId));
if (personAttribute == null)
{
personAttribute = new PersonAttribute(person.PersonID, int.Parse(attributeId));
}...