B
B
BadCats2018-03-18 23:15:19
C++ / C#
BadCats, 2018-03-18 23:15:19

Error CS0103: The name '$exception' does not exist in the current context?

The following error occurs:

public Column(int column)
    {
        this.column = column;
        Counter = column;
        onColumnCreate += new CreateColumn(Cell.Re_Linked_atColumn);
        for (int i = 0; i < Counter; i++)
        {
            cellArr[i] = new Cell(i);
            //Cell_Counter++;
        }


    }

a table column is created.
onColumnCreate += new CreateColumn(Cell.Re_Linked_atColumn);
- is responsible for finding cell neighbors when creating a column.
cellArr[i] = new Cell(i); - заполняем массив ячеек - ячейками

There is also a little trick here:
public static Cell[] cellArr = new Cell[Counter];

    public static event CreateColumn onColumnCreate;
    //public static int Cell_Counter=0;
    int column;
    public static int Counter;

- Counter itself is static and in Re_Linked_atColumnI do the following:
nt c = Column.Counter;
        Column.Counter = c; - что бы помнить значение Counter и при создании нового столбца продолжать с того же места.

Here is the Cell class itself, the instances of which I create
public class Cell
{


    public static List<bool> west = new List<bool>();
    public static List<bool> east = new List<bool>();
    public static List<bool> north = new List<bool>();
    public static List<bool> south = new List<bool>();
    static int RowCount = 0;
    static int ColumnCount = 0;
    int Cell_Index;


    public Cell(int Index)
    {
        this.Cell_Index = Index;
    }

    public int index
    {
        get { return Cell_Index; }
    }

but the problem is that already at the first iteration here:
for (int i = 0; i < Counter; i++)
        {
            cellArr[i] = new Cell(i);
            //Cell_Counter++;
        } - смотрел под отладчиком - смотрел оно один раз заходит в Cell -в конструктор Cell и затем выкидывает из цикла с ошибкой :

System.IndexOutOfRangeException: "Index was out of range."

Here is the screenshot:
5aaec8c536f13727921670.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-03-18
@BadCats

Your array is smaller than Counter. Somewhere in the code, you increased Counter, but the size of the array remained the same.
The fastest way out is to use a List

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question