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 8747931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:26:22+00:00 2026-06-13T12:26:22+00:00

I have a huge list of checks that checks for example if integer is

  • 0

I have a huge list of checks that checks for example if integer is 4 or 10, if it is 4 it changes this int to 10 and Vice versa so my if check would be something like this:

int i = getval();
if (i == 4)
{
    i = 10;
}
else if (i == 10)
{
    i = 4;
}

My question is there another way to do this without the need to check for each condition.

  • 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-13T12:26:23+00:00Added an answer on June 13, 2026 at 12:26 pm

    If you have a huge list you might consider some list structure.

    static Dictionary<int, int> exchange = new Dictionary<int, int>();
    
    static Constructor()
    {
        AddExchangePair(4, 10);
        AddExchangePair(3, 12);
        ...
    }
    
    static void AddExchangePair(int a, int b)
    {
        exchange.Add(a,b);
        exchange.Add(b,a);
    }
    
    public staic bool Exchange(ref int value)
    {
        int newValue = 0;
        bool exchanged = exchange.TryGetValue(value, out newValue);
        if (exchanged) value = newValue;
        return exchanged;
    }
    

    This works for huge lists of exchange pairs.

    If you call AddExchangePair with a duplicate number e.g. (7,14) and (14, 16) you will get an exception. You might have to consider what to do in that case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge checkbox list with different levels and I would like to
I have a huge autocomplete field with a list of exams. This field prepends
I have a huge list of URL's, in the format: http://www.example.com/dest/uk/bath/ http://www.example.com/dest/aus/sydney/ http://www.example.com/dest/aus/ http://www.example.com/dest/uk/
I have a huge list of tuples in this format. The second field of
I have a huge directory list of URLs from my Web site. Example: /folder/folder2/folder3/page.htm
I have a huge word list of over 280.000+ words that is loaded from
I have a huge list of video files from a webcam that have that
I have a huge list of IDs that i need to query through a
I have a huge Ping list and want to clean it. Using PHP I
I have a huge java codebase (more than 10,000 java classes) that makes extensive

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.