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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:50:14+00:00 2026-06-01T15:50:14+00:00

I have a list. If the value that you’ve entered is within that list

  • 0

I have a list. If the value that you’ve entered is within that list – result will be returned. Even if value is outside the result’s range – result will be returned because of mod %. It’s really hard to explain my problem with words, so lets take a look at the code:

        List<int> list1 = new List<int>(){ 0, 1, 2, 3, 4, 5, 6 };
        int value = 3; // what's this number to us?
        string result = "";
        int starting_number = 3;

        if (value == list1[(list1.IndexOf(starting_number) + 2) % list1.Count()])
        { result = "yeah"; }
        else if (value == list1[(list1.IndexOf(starting_number) + 1) % list1.Count()])
        { result = "cool"; }
        else if (value == list1[(list1.IndexOf(starting_number) + 0) % list1.Count()])
        { result = "one"; }
        else if (value == list1[(list1.IndexOf(starting_number) - 1) % list1.Count()])
        { result = "noo"; }
        else {result = "oops cant find it"; }
  • starting_number. This number is constant. All measurments are made in relation to this number.
  • value – the value that we’ve entered. we need to get the result for this value
  • result – just a string

That’s how it works:

starting_number = 3, value = 2 => result = “noo” (because 2 = IndexOf(starting_number)- 1)

starting_number = 6, value = 0 => result = “cool” (6 + 1 = 0)

starting_number = 0, value = 6 => Error will occur. (0 – 1 = 6)

any ideas how to improve the code to get rid of this error? Basically I can grab values is they are “after” starting_number, but I cant grab them “before” starting_number.

  • in case of (6 + 1 = 0): list looks like this 6,0,1,2,3…

  • in case of (0 – 1 = 6): list should be this …4,5,6,0

if you have any questions please ask.. it’s really hard to explain the problem with words, but I guess examples made it more clear.

how do you grab values that are below starting_number?

  • 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-01T15:50:16+00:00Added an answer on June 1, 2026 at 3:50 pm

    If I understand correctly, you want to map all integers to range 0 to Count-1 and your current formula is x % count which works only when x > 0. Then if you want it to work for all values of x try this one (x % count + count) % count

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

Sidebar

Related Questions

We have a table value function that returns a list of people you may
How can i have a tuple that has a list as a value. F.x.
I have a function, that returns the next higher value of a Dictionary-Keys-List compared
I have a list of tuples, each containing a find/replace value that I would
In my .aspx page, I have a dropdown list. The first value that it
I have a list of static key/value pairs that I need to include in
I have an IEnumerable list of date/value pairs that I am returning as a
i have a list of checkboxes that have an incremental list of value. i
I'm have a large list of value types that needs to be given to
I have made same code in Javascript that will change options in drop-down list

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.