本文整理汇总了C#中OrderedBag.Intersection方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedBag.Intersection方法的具体用法?C# OrderedBag.Intersection怎么用?C# OrderedBag.Intersection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedBag
的用法示例。
在下文中一共展示了OrderedBag.Intersection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
OrderedBag<int> newBag = new OrderedBag<int>();
OrderedBag<int> newBag2 = new OrderedBag<int>();
OrderedBag<int> newBag3 = new OrderedBag<int>();
OrderedBag<int> newOrderedBag = new OrderedBag<int>();
OrderedBag<int> newOrderedBag2 = new OrderedBag<int>();
OrderedBag<int> newOrderedBag3 = new OrderedBag<int>();
for (int i = 4; i >= 0; i--)
{
newBag2.Add(numbers[i]);
newOrderedBag2.Add(numbers[i]);
}
for (int i = 5; i < 10; i++)
{
newBag.Add(numbers[i]);
newBag2.Add(numbers[i]);
newOrderedBag.Add(numbers[i]);
newOrderedBag2.Add(numbers[i]);
}
newBag3 = newBag2.Union(newBag);
Console.WriteLine("Union of 6-10 & 1-10 :");
Console.WriteLine("Unordered:");
Console.WriteLine();
foreach (int a in newBag3.list)
Console.Write(a + " ");
Console.WriteLine();
Console.WriteLine("Ordered:");
Console.WriteLine();
foreach (int a in newOrderedBag3.list)
Console.Write(a + " ");
Console.WriteLine();
Console.WriteLine("Adding 9-14 to ordered and unordered list.");
newBag2.Add(12);
newBag2.Add(10);
newBag2.Add(11);
newBag2.Add(14);
newBag2.Add(13);
newBag2.Add(9);
newOrderedBag2.Add(12);
newOrderedBag2.Add(10);
newOrderedBag2.Add(11);
newOrderedBag2.Add(14);
newOrderedBag2.Add(13);
newOrderedBag2.Add(9);
Console.WriteLine();
Console.WriteLine("Unordered Contains 23? : " + newBag3.Contains(23));
Console.WriteLine("Ordered Contains 23? : " + newOrderedBag3.Contains(23));
Console.WriteLine();
newBag3 = newBag.Intersection(newBag2);
newOrderedBag3 = newOrderedBag.Intersection(newOrderedBag2);
Console.WriteLine("Intersection of 6-10 & 1-10 :");
Console.WriteLine();
Console.WriteLine("Unordsered:");
Console.WriteLine();
foreach (int a in newBag3.list)
Console.Write(a + " ");
Console.WriteLine();
Console.WriteLine("Ordered:");
Console.WriteLine();
foreach (int a in newOrderedBag3.list)
Console.Write(a + " ");
Console.WriteLine();
Console.WriteLine("Unordered Contains 6? : " + newBag3.Contains(6));
Console.WriteLine();
Console.WriteLine("Ordered Contains 6? : " + newOrderedBag3.Contains(6));
Console.WriteLine();
newBag3.Remove(6);
newOrderedBag3.Remove(6);
Console.WriteLine();
Console.WriteLine("After removing 6, does unordered bag contain 6? : " + newBag3.Contains(6));
Console.WriteLine();
Console.WriteLine("After removing 6, does ordered bag contain 6? : " + newBag3.Contains(6));
}