How to deal with the immutability of returned structs?
I'm writing a game that has a huge 2D array of "cells". A cell takes only 3 bytes. I also have a class called CellMap, which contains the 2D array as a private field, and provides access to it via a public indexer. Profiling showed that a performance problem is caused by garbage collection of too many Cell objects. So I decided to make Cell a struct (it was a class). But now code like this doesn't work: cellMap[x, y].Population++; I can think of many options, but I don't really like any of them. Make the array public , and write cellMap.Data[x, y].Population = 5; Stop using a CellMap class ,