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

  • Home
  • SEARCH
  • 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 8771529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:48:42+00:00 2026-06-13T17:48:42+00:00

I was just shocked when my application fired an IndexOutOfRanage exception now. I opened

  • 0

I was just shocked when my application fired an IndexOutOfRanage exception now. I opened the Debugger Locals Pane and discovered that my integer crossed it’s boundary? Basically I have something like this in my code:

string folder = Extender.GetSetting<string>("textFolder");
string mlink = folder + "\\" + filename + ".txt";
if(File.Exists(mlink))
{
    string fContent = File.ReadAllText(mlink);
    rtbLearnGuide.Text = fContent;
    string[] strings = fContent.Split(' ');
    for (int i = 0; i < strings.Length; i++, words.Enqueue(strings[i]));
}

The problem here is that i reaches the length of strings[], I have attached a picture below.

Weird For-Loop behaviour

What’s even more weird is that I failed to reproduce this behavior a second time.

NB: I experienced something similar earlier today with this.CreateGraphics(); My code was something like:

var dc = this.CreateGraphics();//and some other stuff

The result was that it failed to draw it even after trying to rerun like 4 times, then I went back to the code and defined dc explicitly, voila it was working. Then I changed it back to var, it was still working :/?

What might be wrong?

EDIT:

I just discovered that changing the order works. For instance:

for (int i = 0; i < strings.Length; words.Enqueue(strings[i]), i++);

doesn’t fire any errors.

  • 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-13T17:48:43+00:00Added an answer on June 13, 2026 at 5:48 pm

    To answer the first part of your question, you are executing the Enqueue before the for loop’s test condition. So

    for (int i = 0; i < strings.Length; i++, words.Enqueue(strings[i]));
    

    should be:

    for (int i = 0; i < strings.Length; i++) words.Enqueue(strings[i]);
    

    Basically, the “increment” portion will always execute before the “test” portion.

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

Sidebar

Related Questions

I was just shocked, that this is allowed: if( int* x = new int(
This is a question for the generic collection gurus. I'm shocked to find that
I'm completely shocked that I can't find anything about how to do this. How
Serious question: I just committed to github and got shocked: Netbeans has transferred my
Just a quick check really. I have an XML file that I will be
I'm a little shocked that (if?) this precise questions hasn't been asked, but 15
First: I'm shocked that I have to ask this question. Nowhere in the docs
I was shocked to learn that OpenMosix is closed . Can you suggest any
I'm about to deploy my new WPF application and I've just noticed in the
This is driving me crazy and I'm shocked that official documentation is absolutely useles.

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.