C# declaring a 2D array

前端 未结 5 1063
梦如初夏
梦如初夏 2021-01-19 17:13

I am trying to setup a 2d array in C# to act as a maze to move a character around, I am having a few issues initialising the array, I am trying to do the below

but t

5条回答
  •  再見小時候
    2021-01-19 17:49

    You can't initialize an array like that other than in a variable declaration. However, the change is simple:

    maze = new int[,] { 
       // As before
    };
    

    As asides:

    • It looks like maze should be an instance variable rather than a static variable. After all, you're initializing it each time you create an instance of Maze
    • You have a finalizer for no reason. Finalizers are very rarely required (or indeed advisable) in C#

提交回复
热议问题