Почему не удаляется элемент из List?
class lol
{
public int id;
public int a = 0;
public int b = 0;
}
static int counter = 0;
static List<lol> myarray = new List<lol>();
static lol returnbyid(List<lol> lst, int id)
{
for (int i = 0; i < lst.Count(); i++)
{
if (myarray[i].id == id)
{
return myarray[i];
}
}
return null;
}
static void Main(string[] args)
{
Random rand = new Random();
for (int i = 0; i < 6; i++)
{
lol tmp = new lol();
tmp.id = ++counter;
tmp.a = rand.Next();
tmp.b = rand.Next();
myarray.Add(tmp);
}
lol ret = returnbyid(myarray, 3);
ret = null; // Вот тут я хотел удалить элемент
}
List<T>.Remove
. для удаления элементов из коллекции. – Dmitry D. 8 янв '16 в 16:51