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


C# IList.Aggregate方法代码示例

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


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

示例1: FindPositionPart

        public static string FindPositionPart(IList<string> parts, int cursorPosition, out int foundPartsIndex, out int cursorInPartPosition)
        {
            cursorInPartPosition = 0;
              var partsComplete = parts.Aggregate(String.Empty, (aggr, s) => aggr + s);
              for (int i = 0; i < parts.Count(); i++) {
            var partsLower = parts.Take(i).Aggregate(String.Empty, (aggr, s) => aggr + s);
            var partsUpper = parts.Take(i + 1).Aggregate(String.Empty, (aggr, s) => aggr + s);

            var b = partsLower.Length;
            var t = partsUpper.Length;

            if ((cursorPosition >= b && cursorPosition < t) || partsUpper == partsComplete) {
              if (parts[i] == WorkDayParser.itemSeparator.ToString() || parts[i] == WorkDayParser.hourProjectInfoSeparator.ToString()) {
            // cursor left of separator
            foundPartsIndex = i - 1;
            var prevPart = parts.ElementAt(foundPartsIndex);
            // find out where in the found part the cursor is, need to use prevpart an its length
            cursorInPartPosition = prevPart.Length;
            return prevPart;
              } else {
            // find out where in the found part the cursor is
            cursorInPartPosition = cursorPosition - b;
            foundPartsIndex = i;
            return parts.ElementAt(i);
              }
            }
              }
              // not found
              foundPartsIndex = -1;
              return String.Empty;
        }
开发者ID:vipwolf,项目名称:moni,代码行数:31,代码来源:WorkDayParserExtensions.cs

示例2: Unpack

 public Borda Unpack(IList<string> files, string key)
 {
     var borda = new Borda();
     return files.Aggregate(borda,
         (b, file) => b + Unpack(file, key));
 }
开发者ID:rmrfhome,项目名称:nanoborda,代码行数:6,代码来源:Packer.cs

示例3: MorphPart

 private static void MorphPart(RenderMeshPart part, IList<PartMorphInfo> morphInfos)
 {
     var count = morphInfos.Any() ? 1.0f / morphInfos.Count() : 1.0f;
     if (part.IsMirrored)
     {
         var verticesDictionary = new Dictionary<uint, Vector3>();
         for (var i = 0; i < part.Points.Count; i++)
         {
             var point = part.Points[i];
             var delta = morphInfos.Aggregate(Vector3.Zero, (current, mi) => current + mi.PointsMorph[i] * mi.Delta) * count;
             foreach (var index in point.Indices)
             {
                 if (!verticesDictionary.ContainsKey(index))
                     verticesDictionary.Add(index, delta);
             }
         }
         for (var i = 0; i < part.Vertices.Length; i++)
         {
             var vertex = part.Vertices[i];
             if (vertex.OriginalPosition.X >= 0.0f && vertex.OriginalPosition.X <= 1.0f)
             {
                 var a = (uint)Math.Abs(vertex.OriginalPosition.Y);
                 var b = (uint)Math.Abs(vertex.OriginalPosition.Z);
                 var point0 = part.BaseVertices[a].Position + verticesDictionary[a];
                 var point1 = part.BaseVertices[b].Position + verticesDictionary[b];
                 vertex.Position = point0 + (point1 - point0) * vertex.OriginalPosition.X;
             }
             else
             {
                 var p = (uint)Math.Abs(vertex.OriginalPosition.X) - 2;
                 var delta = verticesDictionary[p];
                 vertex.Position = part.BaseVertices[p].Position + delta;
                 if (vertex.Position.X > 0.0f == part.IsLeftToRight)
                     vertex.Position.X = 0.0f;
                 if (vertex.OriginalPosition.X < 0.0f)
                     vertex.Position.X *= -1.0f;
             }
             part.Vertices[i] = vertex;
         }
     }
     else
     {
         for (var i = 0; i < part.Points.Count; i++)
         {
             var point = part.Points[i];
             var delta = morphInfos.Aggregate(Vector3.Zero, (current, mi) => current + mi.PointsMorph[i] * mi.Delta) * count;
             foreach (var index in point.Indices)
                 part.Vertices[index].Position = point.Position + delta;
         }
     }
     part.UpdateNormals();
 }
开发者ID:reward-hunters,项目名称:PrintAhead,代码行数:52,代码来源:Morphing.cs

示例4: ShowErrorsAsync

 public static async Task ShowErrorsAsync(IList<string> errors)
 {
     if (errors.Count > 0)
     {
         await ShowErrorAsync(errors.Aggregate((s, next) => s + '\n' + next));
     }
 }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:7,代码来源:ErrorDialog.cs

示例5: ModifyFile

        public static void ModifyFile(string pathToFile, IList<ProjectSolutionMapping> mappings)
        {
            string allText;
            Encoding originalEncoding;
            using (var fileStream = File.OpenText(pathToFile))
            {
                originalEncoding = fileStream.CurrentEncoding;
                allText = fileStream.ReadToEnd();
            }

            if (string.IsNullOrEmpty(allText))
            {
                return;
            }

            if (!AnythingNeedsReplacing(allText, mappings))
            {
                Console.WriteLine(@"nothing to modify in " + pathToFile);
                return;
            }

            Console.WriteLine(@"modifying " + pathToFile);

            allText = mappings.Aggregate(
                allText,
                (current, eachMapping) => current.Replace(eachMapping.OldText, eachMapping.NewText));

            File.WriteAllText(pathToFile, allText, originalEncoding);
        }
开发者ID:handcraftsman,项目名称:SwitchVsVersion,代码行数:29,代码来源:Disk.cs

示例6: OnActivate

 public bool OnActivate(IList<string> args)
 {
     // handle command line arguments of second instance
     Current.MainWindow.Title = args.Any()
                                    ? args.Aggregate((s1, s2) => string.Format("{0}, {1}", s1, s2))
                                    : "Second instance launched";
     return true;
 }
开发者ID:trustsoft,项目名称:Trustsoft.SingleInstanceApp,代码行数:8,代码来源:App.xaml.cs

示例7: CollisionGroup

        public CollisionGroup(IList<SimpleSphereCollider> colliders)
        {
            Colliders = colliders;

            _center = colliders.Aggregate(Vector3.zero, (total, each) => (total + each.transform.position)) / colliders.Count;

            _radius = colliders.Select( _=> (_.transform.position - _center).magnitude + _radius ).Max();
        }
开发者ID:OrangeeZ,项目名称:Crandell,代码行数:8,代码来源:CollisionSystem.cs

示例8: AppendMethodParameters

 private string AppendMethodParameters(string methodName, IList<string> parameters)
 {
     if (parameters.Count == 0)
     {
         return methodName + "()";
     }
     return methodName + ('(' + parameters.Aggregate((a, b) => a + ", " + b) + ')');
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:8,代码来源:VisualStudioCodeElementsFormatter.cs

示例9: GenerateSlantingSegmentsRow

 private static IList<Int32> GenerateSlantingSegmentsRow(IList<Int32> sourceValue, Int32 delta)
 {
     return sourceValue.Aggregate(new List<Int32>(), (acc, value) =>
     {
         acc.AddRange(new[] {value - delta, value + delta});
         return acc;
     });
 }
开发者ID:stdstring,项目名称:hackerrank,代码行数:8,代码来源:Program.cs

示例10: StartProcess

        private static void StartProcess(IList<string> parameters)
        {
            var process = new Process();

            process.StartInfo.FileName = App.CurrentTranspilerPath;
            process.StartInfo.Arguments = parameters.Aggregate((x, y) => x + " " + y);

            process.Start();
        }
开发者ID:JonathanLydall,项目名称:Java-Transpiler-In-C-Sharp,代码行数:9,代码来源:TranspilerStarter.cs

示例11: ValidateDeploymentUpgradeTypeAttribute

 public ValidateDeploymentUpgradeTypeAttribute()
 {
     this.validValues = new List<string>
     {
         UpgradeType.Auto,
         UpgradeType.Manual,
         UpgradeType.Simultaneous
     };
     commaSeparatedUpgradeTypes = validValues.Aggregate((c, n) => c + ", " + n);
 }
开发者ID:Viachaslau,项目名称:azure-sdk-tools,代码行数:10,代码来源:ValidateDeploymentUpgradeTypeAttribute.cs

示例12: ShowErrors

 public static void ShowErrors(IList<string> errors)
 {
     if (errors.Count > 0)
     {
         ShowError(errors.Aggregate((s, next) => s + '\n' + next));
     }
     else
     {
         ShowError("An unknown error has occurred.");
     }
 }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:11,代码来源:ErrorDialog.cs

示例13: performOperation

        protected override int performOperation(IList<int> input)
        {
            if (input.Count == 0)
            {
                return 1;
            }
            if (input.Count == 1)
            {
                return input.First();
            }

            return input.Aggregate((a, b) => a * b);
        }
开发者ID:Stromausfall,项目名称:Patterns,代码行数:13,代码来源:Multiply.cs

示例14: Run

        public static float Run(IList<double> dp0, IList<IList<double>> dpc1)
        {
            IList<LocalPattern> lps1 = new List<LocalPattern>();
            lps1 = dpc1.Aggregate(lps1,
                (current, ts) => current.Concat(GetLocalPatterns(ts, WINDOW_SIZE)).ToList());

            IList<LocalPattern> lps0 = GetLocalPatterns(dp0, WINDOW_SIZE);
            BUCKET_SIZE = (int) (TOP_BUCKET_RATIO*dp0.Count);

            List<List<LocalPatternMatch>> lpmBuckets = GetLocalPatternMatchBuckets(lps0, lps1);

            var allLpms = new List<LocalPatternMatch>();
            foreach (var bucket in lpmBuckets)
            {
                foreach (LocalPatternMatch lpm in bucket)
                {
                    allLpms.Add(lpm);
                }
            }

            int numVertices = allLpms.Count + 2;
            var costMatrix = new int[numVertices, numVertices];

            for (int i = 0; i < allLpms.Count; i++)
            {
                int distToStart = LocalPatternMatch.DistanceToPs(allLpms[i], allLpms.Count, WINDOW_SIZE);
                int distToEnd = LocalPatternMatch.DistanceToPe(allLpms[i], allLpms.Count, WINDOW_SIZE);

                costMatrix[0, i + 1] = distToStart;
                costMatrix[i + 1, numVertices - 1] = distToEnd;
            }

            for (int row = 0; row < numVertices - 2; row++)
            {
                for (int col = 0; col < numVertices - 2; col++)
                {
                    if (row == col)
                        costMatrix[row + 1, col + 1] = 0;
                    else
                        costMatrix[row + 1, col + 1] = LocalPatternMatch.Distance(allLpms[row], allLpms[col],
                            allLpms.Count, WINDOW_SIZE);
                }
            }

            var dijkstra = new Dijkstra.Dijkstra();
            dijkstra.Run(costMatrix, 0);
            return dijkstra.StartToEndDistance;
        }
开发者ID:philllies,项目名称:finalproject,代码行数:48,代码来源:Spade.cs

示例15: ValidateVMSizeAttribute

 public ValidateVMSizeAttribute(bool includeExtraSmall)
 {
     this.validValues = new List<string>
     {
         "Small",
         "Medium",
         "Large",
         "ExtraLarge",
         "A6",
         "A7"
     };
     if (includeExtraSmall)
     {
         this.validValues.Insert(0, "ExtraSmall");
     }
     commaSeparatedVMSizes = validValues.Aggregate((c, n) => c + ", " + n);
 }
开发者ID:xmbms,项目名称:azure-sdk-tools,代码行数:17,代码来源:ValidateVMSizeAttribute.cs


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