public object PopAny() { AcquireWriterLock(); try { object item = null; if (_list.Count > 0) { int index = -1; lock (_random) { index = _random.Next(_list.Count); } item = _list[index]; _list.RemoveAt(index); } return item; } finally { ReleaseWriterLock(); } }
public Array ToShuffledArray(Type elementType) { List copy = new List(ToArray()); Array target = Array.CreateInstance(elementType, copy.Count); for (int i = 0; i < target.Length; ++i) { target.SetValue(copy.PopAny(), i); } return(target); }