本文整理汇总了C#中IEnumerable.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.Intersect方法的具体用法?C# IEnumerable.Intersect怎么用?C# IEnumerable.Intersect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.Intersect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: can_match_5
public void can_match_5()
{
soll = new[] { 1, 2, 3, 4, 5, 6 };
ist = new[] { 1, 2, 3, 4, 5, 7 };
Assert.That(ist.Intersect(soll).Count(), Is.EqualTo(5));
Assert.That(ist.Intersect(soll).Count(), Is.EqualTo(soll.Intersect(ist).Count()));
}
示例2: String
public void String(IEnumerable<string> first, IEnumerable<string> second, IEqualityComparer<string> comparer, string[] expected)
{
if (comparer == null)
{
Assert.Equal(expected, first.Intersect(second));
}
Assert.Equal(expected, first.Intersect(second, comparer));
}
示例3: RequiresConsentAsync
public async Task<bool> RequiresConsentAsync(Client client, ClaimsPrincipal user, IEnumerable<string> scopes)
{
if (client == null) throw new ArgumentNullException("client");
if (user == null) throw new ArgumentNullException("user");
if (!client.RequireConsent)
{
return false;
}
// TODO: validate that this is a correct statement
if (!client.AllowRememberConsent)
{
return true;
}
if (scopes == null || !scopes.Any())
{
return false;
}
var consent = await _store.LoadAsync(user.GetSubjectId(), client.ClientId);
if (consent != null && consent.Scopes != null)
{
var intersect = scopes.Intersect(consent.Scopes);
return !(scopes.Count() == intersect.Count());
}
return true;
}
示例4: SRVCUpdateLogins
private IEnumerable<EmployeeLogin> SRVCUpdateLogins(Helpers.Log.SessionInfo logSession, Repository.Logic.Repository rep,
long employeeId, IEnumerable<string> addLogins, IEnumerable<string> removeLogins)
{
#pragma warning disable 618
logSession.Add($"Try to get employee with id = {employeeId}");
var emp = rep.Get<Repository.Model.Employee>(e => e.EmployeeId == employeeId, false, new string[] { "Logins" }).FirstOrDefault();
if (emp == null)
throw new Exception(string.Format(Properties.Resources.STUFFINGSERVICE_EmployeeNotFound, employeeId));
var existedLogins = emp.Logins.Select(r => r.DomainLogin);
#region Add logins
if (addLogins != null && addLogins.Any())
{
logSession.Add($"Add logins...");
var addLoginsUpper = addLogins
.Except(existedLogins)
.ToArray()
.Select(r => rep.New<Repository.Model.EmployeeLogin>((er) =>
{
er.EmployeeLoginId = emp.EmployeeId;
er.DomainLogin = r;
}))
.ToArray();
logSession.Add($"Add this logins {addLoginsUpper.Concat(r => r.DomainLogin, ",")} for employee id = {employeeId}");
foreach (var r in addLoginsUpper)
emp.Logins.Add(r);
rep.AddRange(addLoginsUpper, saveAfterInsert: false);
}
#endregion
#region Remove rights
if (removeLogins != null && removeLogins.Any())
{
logSession.Add($"Remove logins...");
var removeLoginsUpper = removeLogins
.Intersect(existedLogins)
.ToArray()
.Join(emp.Logins, r => r, er => er.DomainLogin.ToUpper(), (r, er) => er)
.ToArray();
logSession.Add($"Remove this logins {removeLoginsUpper.Concat(r => r.DomainLogin, ",")} for employee id = {employeeId}");
foreach (var r in removeLoginsUpper)
emp.Logins.Remove(r);
rep.RemoveRange(removeLoginsUpper, saveAfterRemove: false);
}
#endregion
rep.SaveChanges();
return emp.Logins.Select(er => AutoMapper.Mapper.Map<EmployeeLogin>(er));
#pragma warning restore 618
}
示例5: Crossover
static IEnumerable<int[]> Crossover(IEnumerable<int> father, IEnumerable<int> mother)
{
IEnumerable<int>
intersect = father.Intersect(mother), motherRest = mother.Except(intersect), fatherRest = father.Except(intersect);
int motherRestHalfSize = motherRest.Count() / 2, fatherRestRestHalfSize = fatherRest.Count() / 2;
yield return intersect.Concat(motherRest.Take(motherRestHalfSize)).Concat(fatherRest.Skip(fatherRestRestHalfSize)).ToArray();
yield return intersect.Concat(motherRest.Skip(motherRestHalfSize)).Concat(fatherRest.Take(fatherRestRestHalfSize)).ToArray();
}
示例6: AssertContainsAll
public void AssertContainsAll(IEnumerable<int> expected, IEnumerable<int> actual)
{
int n1 = expected.Distinct().Count();
int n2 = actual.Distinct().Count();
Assert.AreEqual(n1, n2);
Assert.AreEqual(n1, expected.Intersect(actual).Count());
Assert.AreEqual(n2, actual.Intersect(expected).Count());
}
示例7: SuggestLanguage
internal static string SuggestLanguage(IEnumerable<string> supportedLanguages, IEnumerable<string> preferredLanguages)
{
var intersection = preferredLanguages.Intersect(supportedLanguages);
if (intersection.Any())
return intersection.First();
return supportedLanguages.First();
}
示例8: UpperApproximation
public override IEnumerable<double?[]> UpperApproximation(IEnumerable<double?[]> X)
{
Debug.WriteLine("Standard AS Upper Approximation");
return IndiscernibilityClasses()
.Where(Ix => X.Intersect(Ix).Any())
.Aggregate(
Enumerable.Empty<double?[]>(),
(upX, Ix) => upX.Union(Ix))
;
}
示例9: CheckLiveCell
/**
* Verification of a living cell
* if neighboring cells alive for at least two and no more than 3 then cell is alive
* @param currentGeneration
* @param cell
* @param neighboringCells
* @return if cells alive then true
*/
bool CheckLiveCell(IEnumerable<Cell> currentGeneration, Cell cell,
IEnumerable<Cell> neighboringCells)
{
if (cell != null && neighboringCells != null)
{
int countIntersect = currentGeneration.Intersect(neighboringCells).Count();
return (countIntersect == 2 || countIntersect == 3);
}
else
return false;
}
示例10: GetJaccardSimilarity
public double GetJaccardSimilarity(IEnumerable<int> s1, IEnumerable<int> s2)
{
if (s1.Count() < ShingleSize || s2.Count() < ShingleSize)
{
return double.NaN;
}
int cap = s1.Intersect(s2).Count();
int cup = s1.Union(s2).Count();
return (double)cap / cup;
}
示例11: Negotiate
public static string Negotiate(IEnumerable<string> server, IEnumerable<string> client)
{
if (!server.Any() || !client.Any()) {
return null;
}
var matches = client.Intersect(server);
if (!matches.Any()) {
throw new SubProtocolNegotiationFailureException("Unable to negotiate a subprotocol");
}
return matches.First();
}
示例12: Validate
public bool Validate(IEnumerable<char> data)
{
foreach(var s in Statements)
{
if(data.Intersect(s.Data).Count() < s.ExpectedAtLeast)
{
return false;
}
}
return true && data.Count() >= MinLenght;
}
示例13: Evaluate
public static DetailedEvaluation Evaluate(this SentenceSegmenter segmenter, string paragraph,
IEnumerable<int> realBoundaryIndices)
{
IEnumerable<int> predictedIndices = segmenter.GetBoundaryIndices(paragraph);
// ReSharper disable PossibleMultipleEnumeration
IEnumerable<int> misses = realBoundaryIndices.Except(predictedIndices);
IEnumerable<int> falseAlarms = predictedIndices.Except(realBoundaryIndices);
IEnumerable<int> hits = realBoundaryIndices.Intersect(predictedIndices);
// ReSharper restore PossibleMultipleEnumeration
int eosCandidateCount = GetEosCharCount(segmenter.EosCandidates, paragraph);
return new DetailedEvaluation(hits, misses, falseAlarms, eosCandidateCount, paragraph);
}
示例14: RequiresConsentAsync
/// <summary>
/// Checks if consent is required.
/// </summary>
/// <param name="client">The client.</param>
/// <param name="subject">The user.</param>
/// <param name="scopes">The scopes.</param>
/// <returns>Boolean if consent is required.</returns>
public virtual async Task<bool> RequiresConsentAsync(Client client, ClaimsPrincipal subject, IEnumerable<string> scopes)
{
if (client == null) throw new ArgumentNullException("client");
if (subject == null) throw new ArgumentNullException("subject");
if (!client.RequireConsent)
{
return false;
}
// TODO: validate that this is a correct statement
if (!client.AllowRememberConsent)
{
return true;
}
if (scopes == null || !scopes.Any())
{
return false;
}
// we always require consent for offline access if
// the client has not disabled RequireConsent
if (scopes.Contains(Constants.StandardScopes.OfflineAccess))
{
return true;
}
var consent = await _store.LoadAsync(subject.GetSubjectId(), client.ClientId);
if (consent != null && consent.Scopes != null)
{
var intersect = scopes.Intersect(consent.Scopes);
return !(scopes.Count() == intersect.Count());
}
return true;
}
示例15: ReadTerm
/// <summary>
/// Evaluate a term.
/// </summary>
/// <param name="factor">
/// Left term already read as part of the expression.
/// </param>
/// <returns>Test methods described by the expression.</returns>
/// <remarks>
/// Non-terminal created for left-factoring:
/// {Term'} :=
/// #empty#
/// ^ {Factor}{Term'}
/// </remarks>
private IEnumerable<ITestMethod> ReadTerm(IEnumerable<ITestMethod> factor)
{
if (TryMatch(Intersection))
{
return ReadTerm(factor.Intersect(ReadFactor()));
}
else
{
return factor;
}
}