Accessing variables from a iteration-list of instances of another script

Hello,

I have come across the problem that I do have some scripts of which one needs to create a list of GameObjects and iterate through them. while doing so, I now want it to check certain variables within the script attached to these GameObjects.

I searched for previous questions about this but I have only found seperated solutions, such for iterating through a list and such for accessing variables/methods from another script but I find myself unable to combine those.

if someone could help me that’d be nice.
I’m using C# btw.

#################################################
Edit: for better understanding:

I have some GameObjects in the form of boxes which are placed in a grid shape.
each of the boxes has a script with 2 variables: 1 for the column and 1 for the line. these variables are public so I can set them manually in the inspector.

then I have another script where I use the following line of code in the start method to create a list of boxes:

Box[] boxes = FindObjectsOfType(typeof(Box)) as Box[];

in another method within the same script I then want to iterate through the list and read out the values of the 2 aforementioned variables in order to compare them with values from the current script.

as you can see here, I dont know exactly where the ‘b’ from the foreach loop comes into play:

foreach(Object b in boxes) {
	Box box =	GetComponent<Box>();
	int c = box.getColumn();
	int l = box.getLine();
	Debug.Log(c + " " + l);
}

maybe I’m doing something wrong altogether. if that’s the case please let me know.
any help is appreciated!

Each element of boxes array is Box, so just do it:

foreach(Box b in boxes)
{
    int c = b.getColumn();
    int l  = b.getLine();
    Debug.Log(c + " " + l);
}

Your code tries to get Box component from current GameObject. Moreover this code do it multiple times - for each element in Box.