0

I am trying to fill a two-dimensional array with objects of my class but the debugger marks it as if it had a null value in the assignment operator line and in the line after. I've created a default constructor to prevent that from being the problem. I need it to take the value of

   matrixOfButtons[i, n] = new SpecialButton(i, n);

But it won't, it will stay as null. Why is that if I am already assigning the value with another constructor in the line above?

   protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    int NumberOfRows = 15;
    int NumberOfColumns = 6;
    // Create array with default constructor
    SpecialButton[,] matrixOfButtons = new SpecialButton[NumberOfRows, NumberOfColumns];
        for (int i = 0; i < NumberOfRows; i++)
        {
            for(int n = 0; n < NumberOfColumns; n++)
            {
                matrixOfButtons[i, n] = new SpecialButton(i, n);
                // THE PREVIOUS LINE AND THE ONES THAT FOLLOW DISPLAY 
                //A NULL VALUE FOR matrixOfButtons[i,n] IN THE DEBUGGER.
            }
        }
      }

Constructors for SpecialButton object

public SpecialButton()
        {
        }
public SpecialButton(int row, int column)
        {
            button = new ToggleButton();
            row += 1;
            column += 1;
            Grid.SetRow(button, row);
            Grid.SetColumn(button, column);
        }
  • If i replace your Special button with string, code compiles and runs wihtout errors so I would have to guess the issue is in the constructor for SpecialButton – KnightFox Jun 25 '15 at 17:07
  • [Edit](http://stackoverflow.com/posts/31056492/edit) your question to include code that exhibits the problem. – Dour High Arch Jun 25 '15 at 17:10
  • @KnightFox: You are right, it does look like that is the problem, but I can't quite fix it. I've added the code for both the default constructor and the one with two parameters. Is there anything you can picture that might be causing the problem? – Katie Arriaga M Jun 25 '15 at 18:13
  • @DourHighArch: The code that exhibits the problem is the one I already added. However, I also added the constructors I implemented, as somebody suggested the problem might be in the constructors. Since this is my first attempt at C#/XAML/wpf I can't quite put my finger on it. – Katie Arriaga M Jun 25 '15 at 18:19
  • @KatieArriagaM, you could try putting a breakpoint and zeroing in on the line in the constructor where it fails. – KnightFox Jun 25 '15 at 19:07

0 Answers0