Bamboo.Prevalence.Collections.List.PopAny C# (CSharp) 메소드

PopAny() 공개 메소드

Selects a random item from the list and removes it.
public PopAny ( ) : object
리턴 object
		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();
			}
		}

Usage Example

예제 #1
0
        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);
        }
All Usage Examples Of Bamboo.Prevalence.Collections.List::PopAny