当前位置: 首页>>代码示例>>C#>>正文


C# IEnumerable.Intersect方法代码示例

本文整理汇总了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()));
 }
开发者ID:bjornebjornson,项目名称:LottoNh2,代码行数:7,代码来源:_IEnumerableIntersect.cs

示例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));
 }
开发者ID:chcosta,项目名称:corefx,代码行数:8,代码来源:IntersectTests.cs

示例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;
        }
开发者ID:Lawrence2013,项目名称:Thinktecture.IdentityServer.v3,代码行数:30,代码来源:DefaultConsentService.cs

示例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
        }
开发者ID:kblc,项目名称:Personnel.old,代码行数:59,代码来源:StuffingService.EmployeeLogin.cs

示例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();
 }
开发者ID:sergey-podolsky,项目名称:university,代码行数:8,代码来源:GA.cs

示例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());
        }
开发者ID:CoralSmith,项目名称:3-SadCycle,代码行数:9,代码来源:UnitTest1.cs

示例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();
        }
开发者ID:BrightSoul,项目名称:i18n,代码行数:9,代码来源:LocalizationController.cs

示例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))
                ;
        }
开发者ID:4201715125,项目名称:S4201715125V1,代码行数:11,代码来源:StandardApproximationSpace.cs

示例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;
 }
开发者ID:nazargulov,项目名称:Conways-Game-of-Life,代码行数:19,代码来源:Game.cs

示例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;
        }
开发者ID:mbaago,项目名称:WebCrawler,代码行数:12,代码来源:Jaccard.cs

示例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();
        }
开发者ID:SkightTeam,项目名称:Fleck,代码行数:12,代码来源:SubProtocolNegotiator.cs

示例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;
        }
开发者ID:moravas,项目名称:chat,代码行数:12,代码来源:PasswordValidator.cs

示例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);
        }
开发者ID:diegolinan,项目名称:nuve,代码行数:15,代码来源:SentenceSegmenterEvaluator.cs

示例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;
        }
开发者ID:Rafael-Miceli,项目名称:IdentityServer4,代码行数:44,代码来源:DefaultConsentService.cs

示例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;
   }
 }
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:24,代码来源:TagManager.ExpressionEvaluator.cs


注:本文中的IEnumerable.Intersect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。