Home c# System.IndexOUTOFRANGEEXCEPTION: "The index was out of the boundaries of the array

System.IndexOUTOFRANGEEXCEPTION: “The index was out of the boundaries of the array

Author

Date

Category

Programmers, help!

using system;
Using System.Collections.Genic;
Using System.comPonentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
using system.threading.tasks;
using System.Windows.Forms;
Namespace learnenglish
{
  Public Partial Class Start: Form
  {
    Public String [] WordsandTranslate = New String [] {};
    Public int [] oddnumbers = new int [] {};
    Public int [] evennumbers = New int [] {};
    Public int Count = 0;
    Public int buttonClick = 0;
    Public Start ()
    {
      Initializecomponent ();
    }
    Private Void Label1_Click (Object Sender, Eventargs E)
    {
    }
    Private Void Start_Load (Object Sender, Eventargs E)
    {
      Words Words = New Words ();
      String Text = Words.get ();
      String [] SplitText = Text.Split (',');
      While (True)
      {
        If (Count == SplitText.Length)
        {
          Break;
        }
        WordSandTranslate = SplitText [Count] .split ('-');
        COUNT ++;
      }
      label1.text = WordsandTranslate [0];
      Int Countofletter = WordsandTranslate.Length;
      INT COUNTOFFORFIRST = 0;
      INT COUNTOFFORSECOND = 0;
      For (int i = 1; i & lt; = WordsandTranslate.Length; i + = 2)
      {
        Oddnumbers [Countofforfirst] = i;
        Countofforfirst ++;
      }
      For (int y = 0; y & lt; = WordsandTranslate.Length; Y + = 2)
      {
        Evennumbers [CountofforSecond] = y;
        CountofForSecond ++;
      }
    }
    Private Void Button1_Click (Object Sender, Eventargs E)
    {
      if (textbox1.text == WordsandTranslate [Evennumbers [ButtonClick]]) {
        label1.text = WordsandTranslate [ODDNUMBERS [ButtonClick]];
      }
    }
  }
}

Problem:

for (int i = 1; i & lt; = wordsandtranslate.length; i + = 2)
{
  Oddnumbers [Countofforfirst] = i;
  Countofforfirst ++;
}

Answer 1, Authority 100%

Helping:

Array ODDNUMBERS Not the size you need.

oddnumbers = new int [Wordsandtranslate.length / 2 + WordsandTranslate.Length% 2];
For (int i = 1; i & lt; = WordsandTranslate.Length; i + = 2)
{
 ...

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions