本文整理汇总了C#中Set.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Set.Intersect方法的具体用法?C# Set.Intersect怎么用?C# Set.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set.Intersect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
var setOne = new Set<int>();
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(5);
setOne.Add(6);
var setTwo = new Set<int>();
setTwo.Add(5);
setTwo.Add(10);
Console.WriteLine(setOne);
Console.WriteLine(setTwo);
var union = setOne.Union(setTwo);
Console.WriteLine();
Console.WriteLine(union);
var intersect = setOne.Intersect(setTwo);
Console.WriteLine(intersect);
}
示例2: Main
public static void Main(string[] args)
{
Set<string> s = new Set<string>();
s.AddWord("123");
s.AddWord("234");
s.AddWord("345");
Set<string> s2 = new Set<string>();
s2.AddWord("321");
s2.AddWord("234");
s2.AddWord("345");
Console.WriteLine(s);
Console.WriteLine();
Console.WriteLine(s2);
Console.WriteLine();
Set<string> s3 = s.Sum(s2);
Console.WriteLine(s3);
Set<string> s4 = s.Sub(s2);
Console.WriteLine(s4);
Set<string> s5 = s.Intersect(s2);
Console.WriteLine(s5);
Console.WriteLine();
}
示例3: Main
public static void Main()
{
var set1 = new Set<string>();
var set2 = new Set<string>();
set1.Add("one");
set1.Add("two");
set1.Add("three");
set2.Add("three");
set2.Add("four");
Console.WriteLine(set1);
Console.WriteLine(set2);
Console.WriteLine(set1.Intersect(set2));
Console.WriteLine(set2.Intersect(set1));
Console.WriteLine(set1.Union(set2));
Console.WriteLine(set2.Union(set1));
set1.Remove("five");
set1.Remove("two");
Console.WriteLine(set1);
Console.WriteLine(set1.Find("one"));
Console.WriteLine(set1.Find("two"));
Console.WriteLine(set1.Count);
}
示例4: IntersectTest
public void IntersectTest()
{
Set<int> firstSet = new Set<int>(1, 2, 3, 4, 5);
Set<int> secondSet = new Set<int>(3, 4, 5, 6, 7);
Set<int> resultSet = firstSet.Intersect(secondSet);
Assert.IsTrue(resultSet.Contains(3));
Assert.IsTrue(resultSet.Contains(4));
Assert.IsTrue(resultSet.Contains(5));
}
示例5: TestIfIntersectIntersectsTwoSets
public void TestIfIntersectIntersectsTwoSets()
{
var setOne = new Set<int>();
setOne.Add(5);
setOne.Add(6);
var setTwo = new Set<int>();
setTwo.Add(5);
setTwo.Add(10);
var intersect = setOne.Intersect(setTwo);
Assert.AreEqual(2, intersect.Count);
Assert.AreEqual(false, intersect.Contains(5));
Assert.AreEqual(true, intersect.Contains(6));
Assert.AreEqual(true, intersect.Contains(10));
}
示例6: CheckConcurrencyControlTokens
// <summary>
// Checks:
// 1) Concurrency token is not defined in this Extent's ElementTypes' derived types
// 2) Members with concurrency token should not have conditions specified
// </summary>
private void CheckConcurrencyControlTokens()
{
Debug.Assert(m_viewTarget == ViewTarget.QueryView);
// Get the token fields for this extent
var extentType = m_extent.ElementType;
var tokenMembers = MetadataHelper.GetConcurrencyMembersForTypeHierarchy(extentType, m_edmItemCollection);
var tokenPaths = new Set<MemberPath>(MemberPath.EqualityComparer);
foreach (var tokenMember in tokenMembers)
{
if (!tokenMember.DeclaringType.IsAssignableFrom(extentType))
{
var message = Strings.ViewGen_Concurrency_Derived_Class(tokenMember.Name, tokenMember.DeclaringType.Name, m_extent);
var record = new ErrorLog.Record(ViewGenErrorCode.ConcurrencyDerivedClass, message, m_cellWrappers, String.Empty);
ExceptionHelpers.ThrowMappingException(record, m_config);
}
tokenPaths.Add(new MemberPath(m_extent, tokenMember));
}
if (tokenMembers.Count > 0)
{
foreach (var wrapper in m_cellWrappers)
{
var conditionMembers = new Set<MemberPath>(
wrapper.OnlyInputCell.CQuery.WhereClause.MemberRestrictions.Select(oneOf => oneOf.RestrictedMemberSlot.MemberPath),
MemberPath.EqualityComparer);
conditionMembers.Intersect(tokenPaths);
if (conditionMembers.Count > 0)
{
// There is a condition on concurrency tokens. Throw an exception.
var builder = new StringBuilder();
builder.AppendLine(
Strings.ViewGen_Concurrency_Invalid_Condition(
MemberPath.PropertiesToUserString(conditionMembers, false), m_extent.Name));
var record = new ErrorLog.Record(
ViewGenErrorCode.ConcurrencyTokenHasCondition, builder.ToString(), new[] { wrapper }, String.Empty);
ExceptionHelpers.ThrowMappingException(record, m_config);
}
}
}
}
示例7: TestEmptyIntersection
public void TestEmptyIntersection() {
var set1 = new Set<int>();
var set2 = new Set<int>();
set1.Add(new [] { 1, 2 });
set2.Add(new [] { 3, 4 });
var intersection = set1.Intersect(set2);
Assert.Equals(0, intersection.Count);
}
示例8: TestNonIntersection
public void TestNonIntersection() {
var set1 = new Set<int>();
var set2 = new Set<int>();
set1.Add(new [] { 1, 2 });
set2.Add(new [] { 2, 3 });
var intersection = set1.Intersect(set2);
Assert.Equals(1, intersection.Count);
Assert.True(intersection.Contains(2));
}
示例9: TestIntersection
public void TestIntersection() {
var set1 = new Set<int>();
var set2 = new Set<int>();
Assert.True(set1.Intersect(set2).IsEmpty);
}
示例10: SetIntersectionTest
public void SetIntersectionTest()
{
Set<int> a = new Set<int>();
for(int i = 0; i < 16; i += 2)
{
a.Add(i);
}
Set<int> b = new Set<int>();
for(int i = 0; i < 16; i += 3)
{
b.Add(i);
}
Set<int> inter = a.Intersect(b);
Assert.That(inter.Count, Is.EqualTo(3), "A01");
Assert.That(inter[0], Is.EqualTo(0), "A02");
Assert.That(inter[1], Is.EqualTo(6), "A03");
Assert.That(inter[2], Is.EqualTo(12), "A04");
}