//**************************************** private void AllocateRange <TItem>(out WeakCollection <TItem> collection, int count) where TItem : class, new() { //**************************************** var Items = new TItem[count]; //**************************************** for (var Index = 0; Index < count; Index++) { Items[Index] = new TItem(); } collection = new WeakCollection <TItem>(); collection.AddRange(Items); }
public void AddRange() { var MyCollection = new WeakCollection <object>(); var MyObject1 = new object(); var MyObject2 = new object(); MyCollection.AddRange(new object[] { MyObject1, MyObject2 }); GC.Collect(); Assert.AreEqual(2, MyCollection.Count(), "Items were not added"); GC.KeepAlive(MyObject1); GC.KeepAlive(MyObject2); }