Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:45:45+00:00 2026-06-03T14:45:45+00:00

I am a novice at C#, yet I know I should be able to

  • 0

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:

  1. If settings exist in array 1 (domattributes), run the code on each setting value.
  2. If settings also exist in array 2 (intlattributes), run the code on each setting value contained in either array 1 or array
  3. 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));
        }...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:45:47+00:00Added an answer on June 3, 2026 at 2:45 pm

    You need to declare attributeIds only once, and it must be declared outside the if statement so that it is visible to the rest of the method.

    Try this:

    string[] attributeIds;
    if (!string.IsNullOrEmpty(IntlAttributesSetting))
    {
        string[] domattributeIds = DomAttributesSetting.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        string[] intlattributeIds = IntlAttributesSetting.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        attributeIds = new string[domattributeIds.Length + intlattributeIds.Length];
        Array.Copy(domattributeIds, attributeIds, domattributeIds.Length);
        Array.Copy(intlattributeIds, 0, attributeIds, domattributeIds.Length, intlattributeIds.Length);
    }
    else
    {
        attributeIds = DomAttributesSetting.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
    }
    
    foreach (string attributeId in attributeIds)
    {
        // etc...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very novice question, so apologies if the answer to this is
I have looked around a lot, and not found the answer yet. Maybe it
Hi I have been searching but I can't find the answer. How do I
I already know the answer to this, but wanted to share with the community
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
Python novice here. I am using python2.7.2 on Windows7. I have installed the PyWin32
Consider me a novice to Windows environment and COM programming. I have to automate
This has always bugged the hell out of me. Why are lists like this?
I am writing this to get a more realistic view of what I should
Being a novice at Objective-C, I don't get quite the notion of delegate yet.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.