How to create an if statement for each element within a list C#

Hi everyone, Is there a way to create an if statement for each element within a list? I want each of my buttons do something different but I 'm not sure how to set that up.

public List<ButtonInfo> ListOfButtons;
   public class Buttoninfo
        {
		
            public int ButtonFunction = 0;
        }
Void OnGUI(){
               for (int i = 0; i < ListOfButtons.Count; i++)
                if (GUILayout.Button("Button", GUILayout.Width(125), GUILayout.Height(25)))
                {
                    Buttoninfo*.Value++;*

}
//This is all I could come up with. It’s incredibly inefficient and I would Like to change it

  •      if(ListOfButtons[0].ButtonFunction == 1){}*
    
  •  if(ListOfButtons[1].ButtonFunction == 1){}*
    
  •  if(ListOfButtons[2].ButtonFunction == 1){}*
    
  •  if(ListOfButtons[3].ButtonFunction == 1){}*
    
  •  if(ListOfButtons[4].ButtonFunction == 1){}*
    
  •  if(ListOfButtons[5].ButtonFunction == 1){}*
    

}

Well, in the case you mentioned in your comment, you can just use an array with your strings. Set the strings either as “constants” of make the array public so you can set them in the inspector:

private string[] texts = new string[] {"Blah", "Blah2", "Blah3", "Blah4", "Blah5", "Blah6"};
// or
public string[] texts; // set them in the inspector

// [...]
for (int i = 0; i < ListOfButtons.Count; i++)
{
    if(ListOfButtons*.ButtonFunction == 1){}*

{
Text = texts*;*
}
}
ps. I’m a bit confused. You have the List “ListOfButtons” which holds ButtonInfo instances, but what is “buttonsList”? Does it’s elemets corresponds to the ListOfButtons elements? Why not just one list?

This is pretty trivial using LINQ:

using System.Linq;

ListOfButtons.ForEach(x => {if(x.ButtonFunction == 1) { /* Do something with button x */}})