本文整理汇总了C#中ConcurrentBag.Last方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.Last方法的具体用法?C# ConcurrentBag.Last怎么用?C# ConcurrentBag.Last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentBag
的用法示例。
在下文中一共展示了ConcurrentBag.Last方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WHEN_creating_1K_of_objects_THEN_can_change_property_to_an_object
public void WHEN_creating_1K_of_objects_THEN_can_change_property_to_an_object()
{
var actors = new ConcurrentBag<TestActor>();
for (int i = 0; i < 1000; i++)
{
var id = Guid.NewGuid();
actors.Add(new TestActor { Id = id, Payload = string.Format("Actor Id: {0}", id.ToString()) });
}
Assert.AreEqual(1000, actors.Count);
// Change property by a variable that reference the element in the collection
var actor = actors.First();
Assert.AreNotEqual(Guid.Empty, actor.Id);
actor.Id = Guid.Empty;
Assert.AreEqual(Guid.Empty, actors.First().Id);
// Change property directly to the element in the collection
Assert.AreNotEqual(Guid.Empty, actors.Last().Id);
actors.Last().Id = Guid.Empty;
Assert.AreEqual(Guid.Empty, actors.Last().Id);
// Changing property in a loop
Assert.IsTrue(actors.Where(a => a.Id != Guid.Empty).Any());
foreach (var a in actors)
{
a.Id = Guid.Empty;
}
Assert.IsFalse(actors.Where(a => a.Id != Guid.Empty).Any());
}