C#: How to find data in a List with more then one search variable?

I want to find a value in a custom List based on a couple criterias.

public class BlockData {
	public int x { get; set;}
	public int y { get; set;}
	public int z { get; set;}
	public byte blockType { get; set;}
	public Chunk blockData { get; set;}

	public BlockData(int x, int y, int z, byte blockType, Chunk blockData)
	{
		this.x = x;
		this.y = y;
		this.z = z;
		this.blockType = blockType;
		this.blockData = blockData;
	}
}

And I’d initialize it with data = new List();.

Let’s say I’ve added some data in it.I can do:

world.data.FirstOrDefault(myItem => myItem.x == 5).blockData.update = true;

For example to get the first item with the x variable being 5. But how do I get something like an X Y Z in this case? Aka more then one. I’ve tried something like:

world.data.FirstOrDefault(myItem => myItem.x == updateX myItem.y == updateY myItem.z == updateZ).blockData.update = true;

But this doesn’t work. It returns to me that it didn’t find anything but I believe the current data in the field is correct. What can I do to adjust this so that it gives me the data I need based on an X Y and Z? Is this the proper way, or is there another way/more efficent way of finding data in a List using more the one search variable?

So, try to make simple foreach cycle:

foreach(var item in world.data)
{
   if(x == updateX  y == updateY  z == updateZ)
   {
      item.blockData.update = true;
      break;
   }
}

You sure you don’t want to test your assumption there?

You’re right, I was mixing up the errors. It does work but a variable I was calling wasn’t being declared (new) properly thus it was throwing an null error. I thought it was due to world.data item not being declared, but it was due to blockData.

Sorry about that, but thank you!