[C#] - How to set a array to 0?

Started by
3 comments, last by mobii 19 years ago
How me get all pla = 0?

public class World
{
	public int[,] pla;

	public World(int a, int b)
	{
		int[,] pla = new int [a, b];
	}
}

is there any better way than this?

public class World
{
	public int[,] pla;

	public World(int a, int b)
	{
		int[,] pla = new int [a, b];
		for (int x = 0; x < a; x++)
		{
			for (int y = 0; y < b; y++) pla[x, y] = 0;
		}
	}
}

Advertisement
int[,] pla = new int [a, b];


is good enough :)
C# initializes things to 0 or null when you first make the variable.
If you later want to set all the values to 0 again , there's Array.Clear(Array, int, int).

Regards,
Andre
Andre Loker | Personal blog on .NET
Thanks for help!
Erase meh code...

This topic is closed to new replies.

Advertisement