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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:45:31+00:00 2026-06-09T08:45:31+00:00

I have the following code : public List<IAction> Dispatch(string[] arg) { int time=0; int

  • 0

I have the following code :

 public List<IAction> Dispatch(string[] arg)
   {
       int time=0;
       int i = 0;
       int j = 0;
       List<IAction> t = new List<IAction>(10);
       do
       {
           if (arg[j][0] == '/') // I get index out of bounds here
           {
               Options opt = new Options();                   

               time = opt.Option(arg[j]);
               j++;
           }
           else
           {
               if (int.Parse(arg[j]) >= 0 && int.Parse(arg[j]) <= 20)
               {
                   t.Add(new ComputeParam(int.Parse(arg[j])));
                   i++;
                   j++;                      
               }
           }

       } while (i != arg.Length);
       for (int z = 0; z < t.Count; z++)
       {
           ((ComputeParam)t[z]).Time = time;
       }
       return t;
   }

Why does the error happen… I just pass the arguments and if they are numbers I add them to a list, if not I set an option and move on. What is the problem here?

Edit : I pass 2 /t:Med 2 3
those are the arguments. I aleready checked it arg[1] (in this case) is null, but it’s not.

  • 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-09T08:45:34+00:00Added an answer on June 9, 2026 at 8:45 am

    I see a couple of possible issues here:

    1. If arg[] is empty, you will get the exception
    2. If arg[j] is an empty string, you will get the exception
    3. If you have any options, you will get the exception on a later execution of the loop, because j is being incremented, but i is not.

    I think this will fix it:

    public List<IAction> Dispatch(string[] arg)
    {
       int time=0;
       List<IAction> t = new List<IAction>(10);
       for (int j = 0; j < arg.Length; j++)
       {
           if (!String.IsNullOrEmpty(arg[j]) && arg[j][0] == '/')
           {
               Options opt = new Options();                   
    
               time = opt.Option(arg[j]);
           }
           else
           {
               if (int.Parse(arg[j]) >= 0 && int.Parse(arg[j]) <= 20)
               {
                   t.Add(new ComputeParam(int.Parse(arg[j])));
                   // Don't need to increment i                
               }
           }
    
       }
       for (int z = 0; z < t.Count; z++)
       {
           ((ComputeParam)t[z]).Time = time;
       }
       return t;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following snippet of code: public static List<string> sqlData = new List<string>();
I have the following code: public List<IWFResourceInstance> FindStepsByType(IWFResource res) { List<IWFResourceInstance> retval = new
i have the following code: public static void Serialize() { List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
I have the following code: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get
I have following code public class TEST { public static void main(String arg[]){ try
I have the following code files: public interface IMod { string Name { get;
I have the following code: public class DeserializeAndCompare { public static List<string> IntoXML() {
Hi i have the following code: public List<Person> findAll() { List<Person> copy = new
I have the following code snippet that produces a compilation error: public List<string> batchaddresses;
I have the following code: public class CategoryNavItem { public int ID { get;

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.