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


C# IList.Any方法代码示例

本文整理汇总了C#中IList.Any方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Any方法的具体用法?C# IList.Any怎么用?C# IList.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IList的用法示例。


在下文中一共展示了IList.Any方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Merge

        private static IList<int> Merge(IList<int> left, IList<int> right)
        {
            var result = new List<int>();

            while (left.Any() && right.Any())
            {
                if (left[0] < right[0])
                {
                    result.Add(left[0]);
                    left.Remove(left[0]);
                }
                result.Add(right[0]);
                right.Remove(right[0]);
            }

            while (left.Any())
            {
                result.Add(left[0]);
                left.Remove(left[0]);
            }
            while (right.Any())
            {
                result.Add(right[0]);
                right.Remove(right[0]);
            }

            return result;
        }
开发者ID:didimitrov,项目名称:Algo,代码行数:28,代码来源:Test.cs

示例2: MultilayerPerceptron

        public MultilayerPerceptron(int numInputs, int numOutputs, IList<int> hiddenLayerSizes)
        {
            if (numInputs <= 0)
                throw new NeuralNetworkException($"Argument {nameof(numInputs)} must be positive; was {numInputs}.");

            if (numOutputs <= 0)
                throw new NeuralNetworkException($"Argument {nameof(numOutputs)} must be positive; was {numOutputs}.");

            if (hiddenLayerSizes == null || !hiddenLayerSizes.Any())
                throw new NeuralNetworkException($"Argument {nameof(hiddenLayerSizes)} cannot be null or empty.");

            if (hiddenLayerSizes.Any(h => h <= 0))
            {
                var badSize = hiddenLayerSizes.First(h => h <= 0);
                var index = hiddenLayerSizes.IndexOf(badSize);
                throw new NeuralNetworkException($"Argument {nameof(hiddenLayerSizes)} must contain only positive " +
                                                $"values; was {badSize} at index {index}.");
            }

            NumInputs = numInputs;
            NumOutputs = numOutputs;
            HiddenLayerSizes = hiddenLayerSizes.ToArray();

            Weights = new double[hiddenLayerSizes.Count + 1][];

            for (var i = 0; i < hiddenLayerSizes.Count + 1; i++)
            {
                if (i == 0)
                    Weights[i] = new double[(numInputs + 1) * hiddenLayerSizes[0]];
                else if (i < hiddenLayerSizes.Count)
                    Weights[i] = new double[(hiddenLayerSizes[i-1] + 1) * hiddenLayerSizes[i]];
                else
                    Weights[i] = new double[(hiddenLayerSizes[hiddenLayerSizes.Count - 1] + 1) * numOutputs];
            }
        }
开发者ID:ikhramts,项目名称:NNX,代码行数:35,代码来源:MultilayerPerceptron.cs

示例3: SortItems

        /// <summary>
        /// Sort the items by their priority and their index they currently exist in the collection
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        public static IList<IClientDependencyFile> SortItems(IList<IClientDependencyFile> files)
        {
            //first check if each item's order is the same, if this is the case we'll make sure that we order them 
            //by the way they were defined
            if (!files.Any()) return files;

            var firstPriority = files.First().Priority;

            if (files.Any(x => x.Priority != firstPriority))
            {
                var sortedOutput = new List<IClientDependencyFile>();
                //ok they are not the same so we'll need to sort them by priority and by how they've been entered
                var groups = files.GroupBy(x => x.Priority).OrderBy(x => x.Key);
                foreach (var currentPriority in groups)
                {
                    //for this priority group, we'll need to prioritize them by how they are found in the files array
                    sortedOutput.AddRange(currentPriority.OrderBy(files.IndexOf));
                }
                return sortedOutput;
            }

            //they are all the same so we can really just return the original list since it will already be in the 
            //order that they were added.
            return files;
        } 
开发者ID:dufkaf,项目名称:ClientDependency,代码行数:30,代码来源:DependencySorter.cs

示例4: InitBron

 /// <summary>
 /// 初始化降生点
 /// </summary>
 /// <param name="points">可行走区域</param>
 /// <param name="pins">排除传送阵区域</param>
 public void InitBron(IList<Point> points, IList<Rectangle> pins)
 {
     m_bornPlace = new List<Point>();
     if (m_box.Range != Rectangle.Empty)
     {
         foreach (var p in points)
         {
             if (m_box.Range.Contains(p))
             {
                 if (!pins.Any(x => x.Contains(p)))
                 {
                     m_bornPlace.Add(p);
                 }
             }
         }
     }
     if (m_bornPlace.Count == 0)
     {
         foreach (var p in points)
         {
             if (!pins.Any(x => x.Contains(p)))
             {
                 m_bornPlace.Add(p);
             }
         }
     }
     int index = NumberRandom.Next(m_bornPlace.Count);
     this.m_point = m_bornPlace[index];
 }
开发者ID:abel,项目名称:sinan,代码行数:34,代码来源:BoxBusiness.cs

示例5: Merge

        public static IList<int> Merge(IList<int> left, IList<int> right)
        {
            IList<int> result = new List<int>();

            while (left.Any() && right.Any())
            {
                if (left[0] < right[0])
                {
                    result.Add(left[0]);
                    left.Remove(left[0]);
                }
                else
                {
                    result.Add(right[0]);
                    right.Remove(right[0]);
                }
            }

            while (left.Any())
            {
                result.Add(left[0]);
                left.RemoveAt(0);
            }
            while (right.Any())
            {
                result.Add(right[0]);
                right.RemoveAt(0);
            }

            return result;
        }
开发者ID:didimitrov,项目名称:Algo,代码行数:31,代码来源:Program.cs

示例6: UpdateCounterItems

        public IList<CounterDescriptor> UpdateCounterItems(IList<CounterDescriptor> counterItems)
        {
            //get sites from IIS
            ServerManager iisManager = new ServerManager();
            var sites = iisManager.Sites;

            //build list of names no longer used
            var countersToRemove = new List<string>();
            foreach (var counterItem in counterItems)
            {
                if (!sites.Any(rd => rd.Name==counterItem.Name))
                    countersToRemove.Add(counterItem.Name);
            }
            //remove all contained in removal list
            counterItems = counterItems.Where(item => !countersToRemove.Contains(item.Name)).ToList();

            //add new
            foreach (var iisSite in sites)
            {
                //if we don't have an item with the same name in our list, add it
                if (!counterItems.Any(rd => rd.Name==iisSite.Name))
                {
                    counterItems.Add(CreateDescriptor(iisSite));
                }
            }

            //total
            if (!counterItems.Any(rd => rd.Name == "Total"))
            {
                counterItems.Add(CreateAllMethodRequestsDescriptor());
            }

            //return
            return counterItems;
        }
开发者ID:petemill,项目名称:PerformanceCounter2CloudWatch,代码行数:35,代码来源:IisServerSiteTrafficCountLister.cs

示例7: FormatDeletePatterns

        private string FormatDeletePatterns(IList<ITriple> deletePatterns, string updateGraphUri)
        {
            var deleteCmds = new StringBuilder();
            int propId = 0;
            if (deletePatterns.Any(p => IsGraphTargeted(p) && IsGrounded(p)))
            {
                deleteCmds.AppendLine("DELETE DATA {");
                foreach (var patternGroup in deletePatterns.Where(p => IsGraphTargeted(p) && IsGrounded(p)).GroupBy(p=>p.Graph))
                {
                    deleteCmds.AppendFormat("GRAPH <{0}> {{", patternGroup.Key);
                    deleteCmds.AppendLine();
                    foreach (var deletePattern in patternGroup)
                    {
                        AppendTriplePattern(deletePattern, deleteCmds);
                    }
                    deleteCmds.AppendLine("}");
                }
                deleteCmds.AppendLine("};");
            }
            foreach (var deletePattern in deletePatterns.Where(p=>IsGraphTargeted(p) && !IsGrounded(p)))
            {
                deleteCmds.AppendFormat("WITH <{0}> DELETE {{ {1} }} WHERE {{ {1} }};",
                                        deletePattern.Graph, FormatDeletePattern(deletePattern, ref propId));
            }
            if (deletePatterns.Any(p => !IsGraphTargeted(p) && IsGrounded(p)))
            {
                // Delete from default graph
                deleteCmds.AppendLine("DELETE DATA {");
                foreach (var p in deletePatterns.Where(p => !IsGraphTargeted(p) && IsGrounded(p)))
                {
                    AppendTriplePattern(p, deleteCmds);
                }
                // If an update graph is specified delete from that too
                if (updateGraphUri != null)
                {
                    deleteCmds.AppendFormat("GRAPH <{0}> {{", updateGraphUri);
                    deleteCmds.AppendLine();
                    foreach (var p in deletePatterns.Where(p => !IsGraphTargeted(p) && IsGrounded(p)))
                    {
                        AppendTriplePattern(p, deleteCmds);
                    }
                    deleteCmds.AppendLine("}");
                }
                deleteCmds.AppendLine("};");

            }
            foreach (var deletePattern in deletePatterns.Where(p => !IsGraphTargeted(p) && !IsGrounded(p)))
            {
                var cmd = String.Format("DELETE {{ {0} }} WHERE {{ {0} }};",
                                        FormatDeletePattern(deletePattern, ref propId));
                deleteCmds.AppendLine(cmd);
                if (updateGraphUri != null)
                {
                    deleteCmds.AppendFormat("WITH <{0}> ", updateGraphUri);
                    deleteCmds.AppendLine(cmd);
                }
            }
            return deleteCmds.ToString();
        }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:59,代码来源:SparqlUpdatableStore.cs

示例8: EntityDeleteModel

        public EntityDeleteModel(IList<PropertyDeleteOption> deleteOptions)
        {
            DisplayRecordHierarchy = deleteOptions.Any();
            AssumableDeleteHierarchyWarning = deleteOptions.Any(x => x.ShowOptions);

            if (deleteOptions.Any(x => x.DeleteOption == CascadeOption.AskUser))
                PropertiesDeleteOptions = deleteOptions.Where(x => x.Visible).ToList();
            else
                PropertiesDeleteOptions = new List<PropertyDeleteOption>();
        }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:10,代码来源:EntityDeleteModel.cs

示例9: ForAssignment

        /// <summary>
        /// Returns the submission status for an entire assignment.
        /// </summary>
        public static SubmissionStatus ForAssignment(
            IList<SubmissionStatus> questionStatus)
        {
            var completion = questionStatus.All(q => q.Completion == Completion.Completed)
                ? Completion.Completed
                : questionStatus.Any(q => q.Completion != Completion.NotStarted)
                    ? Completion.InProgress
                    : Completion.NotStarted;

            var late = questionStatus.Any(q => q.Late);

            return new SubmissionStatus(completion, late);
        }
开发者ID:CSClassroom,项目名称:CSClassroom,代码行数:16,代码来源:SubmissionStatus.cs

示例10: GetRuleViolations

        private IEnumerable<FieldDeclarationSyntax> GetRuleViolations(IList<dynamic> fieldsInfo)
        {
            if (fieldsInfo.Any(f => !f.IsCollection))
            {
                return fieldsInfo.Where(f => f.IsCollection).Select(f => f.Syntax as FieldDeclarationSyntax);
            }

            if (fieldsInfo.Any(f => f.IsCollection))
            {
                return fieldsInfo.Where(f => f.IsCollection).Skip(1).Select(f => f.Syntax as FieldDeclarationSyntax);
            }

            return new List<FieldDeclarationSyntax>();
        }
开发者ID:johannes-schmitt,项目名称:DaVinci,代码行数:14,代码来源:Oc4FirstClassCollections.cs

示例11: AugmentCompletionSession

        public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
        {
            if (IsHtmlFile && completionSets.Any())
            {
                var bottomSpan = completionSets.First().ApplicableTo;
                if (!JScriptEditorUtil.IsInJScriptLanguageBlock(_lbm, bottomSpan.GetStartPoint(bottomSpan.TextBuffer.CurrentSnapshot)))
                {
                    // This is an HTML statement completion session, so do nothing
                    return;
                }
            }

            // TODO: Reflect over the ShimCompletionSet to see where the Description value comes from
            //       as setting the property does not actually change the value.
            var newCompletionSets = completionSets
                .Select(cs => cs == null ? cs : new ScriptCompletionSet(
                    cs.Moniker,
                    cs.DisplayName,
                    cs.ApplicableTo,
                    cs.Completions
                        .Select(c => c == null ? c : new Completion(
                            c.DisplayText,
                            c.InsertionText,
                            DocCommentHelper.ProcessParaTags(c.Description),
                            c.IconSource,
                            c.IconAutomationText))
                        .ToList(),
                    cs.CompletionBuilders))
                .ToList();
            
            completionSets.Clear();

            newCompletionSets.ForEach(cs => completionSets.Add(cs));
        }
开发者ID:sanyaade-mobiledev,项目名称:ASP.NET-Mvc-2,代码行数:34,代码来源:ScriptCompletionReplacementSource.cs

示例12: Analyze

        public static Movement Analyze(IList<Movement> movements)
        {
            Movement movement;

            if (movements.Any(x => x > Movement.Higher))
                movement = Movement.Highest;
            else if (movements.Any(x => x > Movement.High))
                movement = Movement.High;
            else if (movements.Any(x => x > Movement.Med))
                movement = Movement.Med;
            else if (movements.Average(x => (double)x) > (double)Movement.Lowest)
                movement = Movement.Low;
            else
                movement = Movement.Lowest;
            return movement;
        }
开发者ID:pkwd,项目名称:SleepHack,代码行数:16,代码来源:AccelerometerToMovementParser.cs

示例13: Execute

        public void Execute(IList<IAggregateCommand> commands, int expectedVersion)
        {
            if (!commands.Any())
            {
                return;
            }

            var rootId = commands.First().AggregateId;

            if (commands.Any(x => x.AggregateId != rootId))
            {
                throw new InvalidOperationException("Can only execute commands for a single aggregate at a time");
            }

            var root = this.repository.GetById(rootId);
            if (root == null)
            {
                root = this.repository.New();
                root.Identity = rootId;
            }

            if (expectedVersion != 0)
            {
                // if we using this command executor multiple times for the same aggregate, when we invoke it we will often have the 
                // verion of the roor prior to the first invocation. Consequently when we check the expected version the second time, 
                // we have a different version and we get an exception. This is supposed to handle that case by remembering what the 
                // version of the root was when we first saw it.
                var rootVersion = root.Version;
                if (this.versions.ContainsKey(root.Identity))
                {
                    rootVersion = this.versions[root.Identity];
                }

                if (rootVersion != expectedVersion)
                {
                    throw new InvalidOperationException(string.Format("Not Expected Version {0}, {1}", expectedVersion, root.Version));
                }
            }

            var exec = new ExecutingCommandExecutor(root);
            exec.Execute(commands, expectedVersion);

            this.repository.Save(root);

            if (expectedVersion != 0 && !this.versions.ContainsKey(root.Identity))
            {
                this.versions[root.Identity] = expectedVersion;
            }
        }
开发者ID:sgmunn,项目名称:Mobile.CQRS,代码行数:49,代码来源:CommandExecutor.cs

示例14: Upload

        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        public static IList<string> Upload(IList<FileItem> files)
        {
            if (files == null || !files.Any())
            {
                return null;
            }

            //远程
            if (_fileUploadType.Equals("REMOTE", StringComparison.CurrentCultureIgnoreCase))
            {
                var req = YunClient.Instance.Execute(new FileUploadRequest { Images = files });
                if (!req.IsError && req.Files != null && req.Files.Any())
                {
                    return req.Files;
                }

                return null;
            }

            //本地
            return
                files.Select(file => new PictureCore(file.GetContent(), file.GetFileName()))
                    .Select(instance => instance.Create())
                    .Where(result => !string.IsNullOrWhiteSpace(result))
                    .ToList();
        }
开发者ID:summer-breeze,项目名称:CaLight,代码行数:31,代码来源:FileManage.cs

示例15: RetriveWidthColumns

        /// <summary>
        /// Retrives the width columns.
        /// </summary>
        /// <param name="columns">The columns.</param>
        /// <returns>Dictionary{System.StringSystem.Int32}.</returns>
        private static Dictionary<string, int> RetriveWidthColumns(IList<string> columns)
        {
            var columnWidthList = new Dictionary<string, int>();

            if (columns != null && columns.Any())
            {
                if (columns[0].Contains(Constants.SplitVerticalBar))
                {
                    for (var i = 0; i < columns.Count(); i++)
                    {
                        var column = columns[i].Split(Constants.SplitVerticalBar);

                        var columnUniqName = !string.IsNullOrEmpty(column[0]) ? column[0] : string.Empty;

                        var columnWidth = 0;
                        try
                        {
                            columnWidth = !string.IsNullOrEmpty(column[1]) && column[1].Length > 1 ? Convert.ToInt32(column[1], CultureInfo.InvariantCulture) : 0;
                        }
                        catch
                        {
                        }

                        columnWidthList[columnUniqName.Trim()] = columnWidth;
                    }
                }
            }

            return columnWidthList;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:35,代码来源:SearchHelper.cs


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