Search code examples
c#unity-game-engineunityscript

Is that possible to add two condition on system.linq ? Unity C#


is that possible to add two condition on system.ling like code below :

int index = Playerx.items.FindIndex (j => j.itemID == IdItem.itemID && j.itemStock < 20);

the code i have add two condition in FindIndex function.

That is to check to find itemID at Playerx.items and Playerx.items itemStock is < 20.

Is That possible ?


Solution

  • Yes, you can add as many conditions as you want.

    In this line:

    (j => j.itemID == IdItem.itemID && j.itemStock < 20)
    

    j.itemID == IdItem.itemID && j.itemStock < 20 - it is delegate and previous line can be replaced:

    (j => {return j.itemID == IdItem.itemID && j.itemStock < 20;})
    

    so, it is body of delegate (method). In method you can use any number of conditions.