struct - C# field must be fully assigned error -


i working on game , getting error. "fields must assigned before control returned caller". can't seem figure out, driving me crazy. here code

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using opentk; using opentk.graphics.opengl; using system.drawing; using system.io;  namespace box2 { struct level  {     private block[,] grid;      public int height     {         {             return grid.getlength(1);         }     }     public int width {                 {             return grid.getlength(0);         }     }      public enum blocktype     {         solid,         empty,         platform,         ladder,         ladderplatform     }        struct block     {         private blocktype type;         private int posx, posy;         private bool solid, platform, ladder;          public blocktype type         {             { return type; }         }         public int x         {             { return posx; }         }         public int y         {             { return posy; }         }         public bool issolid         {             { return solid; }         }         public bool isplatform         {             { return platform; }         }         public bool isladder         {             { return ladder; }         }          private block[,] grid;         private string filename;         public point playerstartapos;          public block(blocktype type, int x, int y)         {             this.posx = x;             this.posy = y;             this.type = type;             this.ladder = false;             this.solid = false;             this.platform = false;              switch (type)             {                 case blocktype.ladder:                     ladder = true;                     break;                 case blocktype.ladderplatform:                     ladder = true;                     platform = true;                     break;                 case blocktype.solid:                     solid = true;                     break;                 case blocktype.platform:                     platform = true;                     break;                 default:                     break;             }         }           public block this[int x, int y]         {                         {                 return grid[x, y];             }             set             {                 grid[x, y] = value;             }         }         public string filename         {             { return filename; }         }          public void level (int width, int height)         {             grid = new block[width, height];             filename = "none";             playerstartapos = new point(1,1);              (int x=0; x < width; x++)             {                 (int y =0; y< height; y++)                 {                     if (x == 0 || y ==0 || x ==width -1 || y == height -1)                     {                         grid[x, y] = new block(blocktype.solid, x, y);                     }                     else                     {                         grid[x, y] = new box2.level.block(blocktype.empty, x, y);                     }                 }             }         }     } } 

}

its means fields in struct should initialized in constructor

you forgot initialize these fields in block struct

        private block[,] grid;         private string filename;         public point playerstartapos; 

but recommend use class in case when use struct?


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -