Question by
nexusgeniuz · Aug 14, 2016 at 02:37 PM ·
c#scripting problemlistcustom class
How to remove an item from a list of custom variables
I have an intVector2 class
public class intVector2
{
public int x;
public int y;
public intVector2(int _x, int _y)
{
x = _x;
y = _y;
}
}
In other script, I have created a list of them
List<intVector2> allowedPoss = new List<intVector2>();
How do I remove some items from it?
allowedPoss.Remove(new intVector2(1, 1)); //Doesn't works
P.S. sorry for my English.
Comment
Answer by jgodfrey · Aug 14, 2016 at 08:41 PM
Generally, you can remove an item from a list by it's index or a reference to the actual item itself.
For the index, use:
allowedPoss.RemoveAt(0) // remove the first item in the list
To remove an item by its reference, use:
allowedPoss.Remove(someIntVector);