C# - Check if one list contains the same elements as another?

Hey, I’m currently working on the crafting system for my game. I have an item database, recipe database, and an inventory. Inside the recipe database, I have a list of Items that the player must have inside their inventory to craft the item.

Here’s where my problem is. I’m trying to check whether the player has ALL of the items that are inside the recipe list, inside their inventory. I’m presuming that I’ll have to use some sort of loop to check if each item which is inside the recipe is in the player’s inventory, but I have been trying for the past three hours to no avail.

Just a tip or two that will point me in the right direction will be hugely appreciated!

Thanks!

You need to take a time and study some basic algoritms. Some simple programing tutorial will teach you some basic algorithms like this.

For example, I found this:
http://forum.unity3d.com/threads/185095-Unity-C-Tutorial-Series

I wrote a sample js (not compiled) script that do something like it.

var hasAll = true;
var requiredList: Item[];
var inventory: Item[];

for (var required in requiredList) {
	var found = false;
	for (var obj in inventory) {
		if (obj.type == required.type && obj.amount >= required.amount) 
                   found = true;
	}
	
	if (!found) hasAll = false;
}

if (hasAll) {
	// create object
}	else {
	Debug.Log("Got to work!");
}