本文整理汇总了C#中ConcurrentBag.AsEnumerable方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.AsEnumerable方法的具体用法?C# ConcurrentBag.AsEnumerable怎么用?C# ConcurrentBag.AsEnumerable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentBag
的用法示例。
在下文中一共展示了ConcurrentBag.AsEnumerable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldReturnProperSubsetOfNumberArray
public void ShouldReturnProperSubsetOfNumberArray()
{
int[] numbers = new int[] { 1, 2, 3, 4, 3, 6, 4, 8, 17, 42, 6 };
ConcurrentBag<int> initialBag = new ConcurrentBag<int>(numbers);
UniqueRandomNumberGenerator g = new UniqueRandomNumberGenerator(numbers);
const int GeneratedRandomNumberCount = 3;
// Sanity check on test data
Debug.Assert(
GeneratedRandomNumberCount < initialBag.Count,
String.Format("The generated random number count {0} must be less than the count of initial numbers {1} for this test.", GeneratedRandomNumberCount, initialBag.Count));
Debug.WriteLine("Random Numbers");
int number = 0;
ConcurrentBag<int> actualBag = new ConcurrentBag<int>();
for (int i = 1; i <= GeneratedRandomNumberCount; i++)
{
number = g.NewRandomNumber();
actualBag.Add(number);
}
HashSet<int> initialSet = new HashSet<int>(initialBag.AsEnumerable());
HashSet<int> actualSet = new HashSet<int>(actualBag.AsEnumerable());
Assert.IsTrue(
actualSet.IsProperSubsetOf(initialSet),
"Generated numbers should be a subset of the initial numbers.");
}