I've writen void that returns List<> of objects. But it crashes with:
StackOverflowException: The requested operation caused a stack overflow. System.Collections.Generic.List'1[T].set_Capacity (System.Int32 value) (at <6073cf49ed704e958b8a66d540dea948>:0) System.Collections.Generic.List'1[T].EnsureCapacity (System.Int32 min) (at <6073cf49ed704e958b8a66d540dea948>:0) System.Collections.Generic.List'1[T].AddWithResize (T item) (at <6073cf49ed704e958b8a66d540dea948>:0)
Here is my code:
public List<Object> MyObjects;
public List<Object> AllObjectsExcluding(string excludedObjectId)
{
List<Object> objects = new List<Object>();
foreach (Object object in MyObjects)
{
if (object.id != excludedObjectId)
{
objects.Add(object); //StackOverflowException
}
}
return objects;
}
public class Object
{
public string id;
}