Array to Switch Statement

{

	//Banana ScoreToggle
	public Sprite[] enabled_priceSprites;// Prices
	
	public Button Banana_price_Button;

	void Start()
	{
		Banana_price_Button = Banana_price_Button.GetComponent<Button>();
	}

	
	public void bananScoreButton()
	{
		// Am not sure how to implement switch statement for the above array?

		switch(enabled_priceSprites)
		{

			case enabled_priceSprites[0]:
			Banana_price_Button.image.sprite = enabled_priceSprites[0];
			break;	   

			case enabled_priceSprites[1]:
			Banana_price_Button.image.sprite = enabled_priceSprites[1];
			break;

		    case enabled_priceSprites[2]:
			Banana_price_Button.image.sprite = enabled_priceSprites[2];
			break;
		}
	}


}

I would like to know how to use the array created above in the switch statement. As I have different price labels which will be assigned in the list. Is it better to use Switch or if else statement?

Thanks.

You need to use a for loop or a foreach loop instead. In there, you can do an if statement (Or switch case) to check if you have the right values:

public Sprite[] enabled_priceSprites;

public void SomeFunction()
{
  for(int i = 0; i < enabled_priceSprites.length; i++)
  {
    if(enabled_priceSprites _== /*Whatever you want*/)_

{
//Do stuff
}
}
}

Switch statements are limited to switching over integer values - usually ints, but also enums, as those are only ints with fancy dresses.

I’m not sure what you’re trying to do, but you can’t do it with a switch statement. If you’re trying to check equality of arrays (those are arrays you have there, not lists), remember that the built in Equals method does NOT consider arrays containing the same elements as equal, so you’ll have to write the array equals method yourself.