C# Array Issue

Pretty simple code, really don’t understand why I can’t reassign arrays in these circumstances (error CS0165: Use of unassigned local variable `trapToChoose’):

	int[] trapToChoose;

	switch (gameManagerScript.landscape)
	{
	case "City":
		if (floorNumber < 51)
		{
			trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
		}
		else if (floorNumber > 50 && floorNumber < 101)
		{
			trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
		}
		else if (floorNumber > 100)
		{	
			trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
		}
		break;
	case "Forest":
		if (floorNumber < 51)
		{
			trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
		}
		else if (floorNumber > 50 && floorNumber < 101)
		{
			trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
		}
		else if (floorNumber > 100)
		{
			trapToChoose = new int[] {20, 50, 70, 100, 100, 100};
		}
		break;
	default:
		print (" PopTrap Script Error");
		trapToChoose = new int[] {0, 0, 0, 0, 0, 0};
		break;
	}

	randomPicker = (int) Mathf.Round(Random.Range(0, 100));
	
	if (randomPicker <= trapToChoose[0])
		chosenTrap = 0;
	else if (randomPicker > trapToChoose[0] && randomPicker <= trapToChoose[1])
		chosenTrap = 1;

Also, would love to know why I am forced to use the {} for the If statement inside a switch (embedded statement error)

The problem is that the compiler sees a way through your code that has you using ‘trapToChoose’ without initializing it. In this case, the problem happens if ‘landscape’ is something other than ‘City’. ‘trapToChoose’ is not initialized, and therefore your use of it on line 14 is an error.

Note I did not get an error when I removed the {} from the ‘if’ statement.

int trapToChoose = new int[6];