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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:41:48+00:00 2026-06-01T02:41:48+00:00

I am trying to solve a problem. This program contains all the edge in

  • 0

I am trying to solve a problem. This program contains all the edge in a graph. The shortest path from source to destination is to find out. I have function named dotest as below.

 public void dotest()
    {
        List<edge> tlist;
        Int32  x;
        setall();
        Int32 ind;
        foreach (edge e1 in alltest)
        {
            tlist = new List<edge>(alledge);

            ind = 0;
            foreach (edge e2 in tlist)
            {
                if (e2.s == e1.s && e2.d == e1.d)
                {
                    break;
                }
                ind++;


            }
            tlist.RemoveAt(ind);



            x=shortpath(tlist, start, destination);
            if (x != -1)
                Console.WriteLine("{0}", x);
            else
                Console.WriteLine("Infinity");

        }


    }

Describing the above code. The code already contains list of alledge(all the edge or path). I have got series of input that contains list of edge to cut off and I have to find the shortest path of the new updated edge list. I compiled my test case and some of test case worked. But for some test case it have error message as.

Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
at System.Collections.Generic.List1[ch_2_3_27.Solution+edge].RemoveAt (Int32 index) [0x00000] in :0
at ch_2_3_27.Solution.dotest () [0x00000] in :0
at ch_2_3_27.Solution.Main (System.String[] args) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
at System.Collections.Generic.List
1[ch_2_3_27.Solution+edge].RemoveAt (Int32 index) [0x00000] in :0
at ch_2_3_27.Solution.dotest () [0x00000] in :0
at ch_2_3_27.Solution.Main (System.String[] args) [0x00000] in :0

I really cannot locate out error and I think all other parts works fine. Anybody can help??

And Edge(edge) above is a struct with members s,d,w(source, destination, weight all Int 32)

  • 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-01T02:41:49+00:00Added an answer on June 1, 2026 at 2:41 am

    The error is pretty clear actually. You are trying to remove an item from tlist at a certain index. However, that index does not have a value.

    If I were to guess, I would say that this only happens whenever nothing in your tlist matches if (e2.s == e1.s && e2.d == e1.d), so you end up with a +1 over the actual index of the tlist array.

    To elaborate further, let’s assume for simplicity that tlist has 1 item, then the index to use that item will be 0. If your if does not work, then you will set ind++, thus setting ind to 1. When you try to remove from the index at 1, then you get your error because there is only an object in the 0 index, and nothing in the 1 index

    I would change the code to something more like this

            ind = -1;
            foreach (edge e2 in tlist)
            {
                ind++;
                if (e2.s == e1.s && e2.d == e1.d)
                {
                    break;
                }
            }
            if(ind != -1)
                tlist.RemoveAt(ind);
    

    I would say to just do the RemoveAt inside of the if, however, that will result in a modified collection exception, so I believe this is the best solution.

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

Sidebar

Related Questions

Trying to solve this problem . I would like to learn how the bootstrapper
I am trying to solve this problem. I have a series of SELECT statements
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they
I'm trying to solve this problem, its not a homework question, its just code
I'm trying to solve this problem for a long time. I have 2 forms,
I've been trying to solve this problem for a number of days now but
I have been trying to solve this problem for a while, but couldn't with
I've been trying to solve this problem for hours now and i cannot figure
I've been trying to solve this problem for a while now and I can't
Background All day long I've been trying to solve a problem, I read all

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.