Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Strange behaviour with List C#

$
0
0
Hi I have an issue with List in my code (or something is off elsewhere). I have a class Chunk which holds some terraintiles. I add Chunks to a List array in my main class. private List chunks = new List(); Chunk newChunk = new Chunk(0, 0); newChunk.GRID_SIZE = GRID_SIZE; newChunk.TILE_SIZE = TILE_SIZE; newChunk.InitiateTerrain(); chunks.Add(newChunk); Then I have a help method Chunk getChunkAt(int xPos, int yPos) { foreach(Chunk chunk in chunks) { if(chunk.x == xPos && chunk.y == yPos) { return chunk; } } return null; } This method finds Chunks, I have even logged just before the "return" statement. The if statement works, it finds chunk.x and chunk.y but if I log the chunk object, it returns null, no matter how I access it. chunks[0] // This returns null getChunkAt(0,0) // This returns null etc... What am I doing wrong. I heard something about "as-cast" issues with C# but I dont understand what Im missing with casting. Im using List and although I cast it to (Chunk) it still turns up to null.

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>