For a 2D tile based game I am developing I just made a 2D array of tile.cs structs, this tile struct contains basic tile information (i.e. tile type, draw frame, etc...). I thought making a array of structs for tile data would be better than creating a array of class types (as structs do not need a memory reference and are allocated on the stack). I think using structs did indeed lower memory usage aswell.
The problem I have is, structs can act very differently to classes sometimes, and it just confuses me. Say I have a x int value in a struct, and I want to incrementt that x value by 1. Typing struct[index].x++ just does not let me? Why??
I have a feeling that it may be because of the following quote from MSDN on structs:
Structs are copied on assignment. When a struct is assigned to a new variable, all the data is copied, and any modification to the new copy does not change the data for the original copy. This is important to remember when working with collections of value types such as Dictionary<string, myStruct>.
What do other programmers think? Use structs or classes in this case. The size of the array that I am making is 16000x4000, so very large.
All replies are appriciated, thanks.