Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

Array like php to C#

Started by kjarli Dec 2, 2008 at 4:44 AM 2 replies 1.2k views
Original Post
kjarli
kjarli
I got the following thing in php, how do you write this for arrays in C#?

$x = 100;
$y = 50;
for($i = 0; $i < $x; $i++) {
	for($j = 0; $j < $y; $j++) {
		$array[$i][$j] = new Tile();
	}
}
It will be used like:

if($build == Unit::TANK) {
	if($array[4][10]->isType(Tile::LAND)) && $array[4][10]->hasFactory($owner)) {
		$array[4][10]->addObject(Unit::TANK, $owner);
	}
}
I've tried several things, but it seems php is the only language that uses "arrays" which you can index yourself...
bubu LV
bubu LV
Tile[,] arr = new Tile[x, y];arr[4, 10] = new Tile();arr[4, 10].addObject(...);


[Edited by - bubu LV on December 2, 2008 5:00:03 AM]
kjarli
kjarli
How can i init an entire array? like, x = 100, y = 50
bubu LV
bubu LV
Use for loop in same way you use it in php.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.