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


C# IEnumerable.Aggregate方法代码示例

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


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

示例1: BuildTableSql

 static string BuildTableSql(IEnumerable<string> tablesToDelete)
 {
     string sql = tablesToDelete.Aggregate(string.Empty, (current, tableName) =>
                 current + string.Format("delete from [{0}];", tableName));
     sql += tablesToDelete.Aggregate(String.Empty, (current, tableName) =>
         current + string.Format("IF EXISTS (SELECT 1 FROM sys.identity_columns WHERE [object_id] = OBJECT_ID(N'{0}', N'U') "
                  + "AND last_value IS NOT NULL) BEGIN DBCC CHECKIDENT('{0}', 'RESEED', 0) END;", tableName));
     return sql;
 }
开发者ID:Tjitse,项目名称:sogeti.capstone,代码行数:9,代码来源:DatabaseDataDeleter.cs

示例2: Calculate

 public int Calculate(Operation op, IEnumerable<int> arguments)
 {
     switch (op)
     {
         case Operation.Sum:
             return arguments.Aggregate(0, (a, b) => a + b);
         case Operation.Product:
             return arguments.Aggregate(1, (a, b) => a * b);
         case Operation.Aseq:
             //return arguments.Aggregate(1, (a, b, c ) => );
         default:
             throw new ArgumentOutOfRangeException(nameof(op), op, "unknown operation");
     }
 }
开发者ID:damdud,项目名称:Lab02,代码行数:14,代码来源:3.cs

示例3: LogUnresolvedConstructor

 private void LogUnresolvedConstructor(IEnumerable<ParameterInfo> unresolvedDependencies, ref StringBuilder unresolvedDependenciesMessage)
 {
     unresolvedDependenciesMessage = unresolvedDependenciesMessage ?? new StringBuilder();
     string message = unresolvedDependencies.Aggregate(string.Empty, (str, pi) => str + pi.ParameterType);
     this.Log.WriteDebug("Ignoring constructor, following dependencies didn't have a registration:" + message);
     unresolvedDependenciesMessage.Append("Constructor: ").AppendLine(message);
 }
开发者ID:endjin,项目名称:openrasta-stable,代码行数:7,代码来源:ObjectBuilder.cs

示例4: CombineHashCodes

 private static int CombineHashCodes(IEnumerable<object> objs)
 {
     unchecked
     {
         return objs.Aggregate(17, (current, obj) => current * 23 + (obj != null ? obj.GetHashCode() : 0));
     }
 }
开发者ID:chavanatul727,项目名称:magazine-website-mvc-5,代码行数:7,代码来源:ValueObject.cs

示例5: SplitWithSeparator

        public static IEnumerable<KeyValuePair<string, string>> SplitWithSeparator(this string str, IEnumerable<string> separator,
			StringComparison comparisonType = StringComparison.CurrentCulture, StringSplitOptions options = StringSplitOptions.None)
        {
            IEnumerable<KeyValuePair<int, string>> indexes = new Dictionary<int, string>();
            indexes = separator.Aggregate(indexes, (current, s) => current.Union(str.IndexOfAll(s, comparisonType).ToDictionaryValue(i => str.Substring(i, s.Length))));
            int lastIndex = 0;
            var list = new List<KeyValuePair<string, string>>();
            foreach (KeyValuePair<int, string> kvp in indexes.OrderBy(a => a.Key))
            {
                string substring = str.Substring(lastIndex, kvp.Key - lastIndex);
                list.Add(new KeyValuePair<string, string>(substring, kvp.Value));
                lastIndex += substring.Length + kvp.Value.Length;
            }
            list.Add(new KeyValuePair<string, string>(str.Substring(lastIndex), null));
            return list.Where(a =>
            {
                switch (options)
                {
                    case StringSplitOptions.None:
                        return true;
                    case StringSplitOptions.RemoveEmptyEntries:
                        return a.Key != "";
                    default:
                        throw new NotSupportedException("unrecognized StringSplitOptions");
                }
            });
        }
开发者ID:kellyselden,项目名称:Libraries,代码行数:27,代码来源:StringExtensions.cs

示例6: TakeExchangesAsync

        public Task<IEnumerable<rate>> TakeExchangesAsync(IEnumerable<string> currencies, string baseCurrency, IEnumerable<string> columnsList = null)
        {
            // if there weren't any selections - default parameter
            if (columnsList == null) columnsList = new List<string> {"*"};

            currencies = currencies.Select(x => x += baseCurrency);

            // provides async result in the caller
            var tcs = new TaskCompletionSource<IEnumerable<rate>>();

            var resource = String.Format(@"yql?q=select {3} from yahoo.finance.xchange {0}{1}{2}",
                                          "where pair in (%22" + currencies.Aggregate((a, b) => String.Format("{0}%22,%22{1}", a, b)) + "%22)",
                                          "&format=json",
                                          "&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys",
                                          columnsList.Aggregate((a, b) => a + "," + b))
                .HtmlDecode();

            var request = new RestRequest(resource, Method.GET);

            _client.ExecuteAsync<RootObject>(request, result => tcs.SetResult(result == null
                ? null
                : result.Data.Query.Results.Rate));

            return tcs.Task;
        }
开发者ID:kneefer,项目名称:CurrencyCalc,代码行数:25,代码来源:YahooRest.cs

示例7: BuildMessage

        private static string BuildMessage(IEnumerable<string> names)
        {
            const string MESSAGE = "Missing values for the following mandatory elements: {0}";
            string missingElements = names.Aggregate("", (s, s1) => s + (s.Any() ? ", " : "") + s1);

            return string.Format(MESSAGE, missingElements);
        }
开发者ID:erminas,项目名称:smartapi,代码行数:7,代码来源:MissingElementValueException.cs

示例8: TracingCallTreeConvertor

        public TracingCallTreeConvertor(IEnumerable<TracingCallTree> tracingCallTrees)
        {
            _globalAggregatedValues = new TracingGlobalAggregatedValues();

            var flattenedTreeList = new List<TracingCallTreeElem>();
            foreach (TracingCallTree callTree in tracingCallTrees)
            {
                _globalAggregatedValues.TotalActiveTime += callTree.UserModeDurationHns + callTree.KernelModeDurationHns;
                FlattenCallTree(callTree.RootElem, flattenedTreeList);
            }

            _aggregators = flattenedTreeList.GroupBy(
                elem => elem.MethodMetadata).Select(
                    grouping =>
                        {
                            MethodMetadata methodMetadata = grouping.Key;
                            var aggregator = new TracingMethodAggregator(methodMetadata);
                            aggregator.AggregateRange(grouping);
                            return aggregator;
                        });

            _globalAggregatedValues.TotalCycleTime = _aggregators.Aggregate((ulong) 0,
                                                                            (sum, methodAgr) =>
                                                                            sum + methodAgr.CycleTime);

            CreateMethodByMetadataDictionary();
            // InterconnectMethodCalls(aggregators);
            CreateCriteriaContext();
            PopulateSourceFiles();
        }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:30,代码来源:TracingCallTreeConvertor.cs

示例9: ComputeView

 public IEnumerable<System.Drawing.Rectangle> ComputeView(IEnumerable<MangaParser.Graphics.IPolygon> polygons)
 {
     // Union over all bits
     return new Rectangle[] { polygons.Aggregate(
         polygons.First().BoundingBox,
         (Rectangle res, IPolygon p2) => Rectangle.Union(res, p2.BoundingBox)) };
 }
开发者ID:fpicalausa,项目名称:mangareader,代码行数:7,代码来源:FullPageViewer.cs

示例10: PrettyPrint

 public static string PrettyPrint(IEnumerable<PositionInText> positions)
 {
     return positions.Aggregate(
                         "positions: ",
                         (res, next) => res + ", " + next.ToString()
                      );
 }
开发者ID:javachengwc,项目名称:many-ql,代码行数:7,代码来源:PositionPrinter.cs

示例11: AddUniqueConstraint

        public IEnumerable<string> AddUniqueConstraint(string tableName, IEnumerable<string> columnNames, string constraintName)
        {
            string columns = columnNames.Aggregate(String.Empty, (current, column) => current + (Escape(column) + ","));
            columns = columns.TrimEnd(',');

            yield return string.Format("CREATE UNIQUE INDEX {0} ({1}) ON {2}", Escape(constraintName), columns, tableName);
        }
开发者ID:nachojammers,项目名称:MigSharp,代码行数:7,代码来源:TeradataProvider.cs

示例12: Calculate

 public int Calculate(Operation op, IEnumerable<int> arguments)
 {
     switch (op)
     {
         case Operation.Sum:
             return arguments.Aggregate(0, (a, b) => a + b);
         case Operation.Product:
             return arguments.Aggregate(1, (a, b) => a * b);
         case Operation.Ndec:
             return IsNonDecreasingSequence(arguments);
         case Operation.Aseq:
             return IsArithmeticSequence(arguments);
         default:
             throw new ArgumentOutOfRangeException(nameof(op), op, "unknown operation");
     }
 }
开发者ID:Mehrunes,项目名称:Lab02,代码行数:16,代码来源:3.cs

示例13: GetGenericParamString

 private static string GetGenericParamString(IEnumerable<string> typeParamString)
 {
     var genericParamString = typeParamString
         .Aggregate("", (s, i) => string.Format("{0}{1},", s, i))
         .TrimEnd(',');
     return genericParamString;
 }
开发者ID:pazjacket,项目名称:posaunehm-_-Friendly.PinInterface.Generator,代码行数:7,代码来源:TypeWrapper.cs

示例14: createSettingsFile

        /// <summary>Creates a settings file. Settings files include teams participating in the save, as well as the default import/export folder.</summary>
        /// <param name="activeTeams">The active teams.</param>
        /// <param name="folder">The default import/export folder.</param>
        private static void createSettingsFile(IEnumerable<Dictionary<string, string>> activeTeams, string folder)
        {
            var s1 = "Folder$$" + folder + "\n";
            var s2 = activeTeams.Aggregate("Active$$", (current, team) => current + (team["ID"] + "$%"));
            s2 = s2.Substring(0, s2.Length - 2);
            s2 += "\n";

            var stg = s1 + s2;

            SaveFileDialog sfd = null;
            Tools.AppInvoke(
                () =>
                    {
                        sfd = new SaveFileDialog
                            {
                                Title = "Save Active Teams List",
                                Filter = "Active Teams List (*.red)|*.red",
                                DefaultExt = "red",
                                InitialDirectory = App.AppDocsPath
                            };
                        sfd.ShowDialog();
                    });

            if (String.IsNullOrWhiteSpace(sfd.FileName))
            {
                return;
            }

            var sw = new StreamWriter(sfd.FileName);
            sw.Write(stg);
            sw.Close();
        }
开发者ID:jaosming,项目名称:nba-stats-tracker,代码行数:35,代码来源:REDitor.cs

示例15: GenerateGenreFilter

 public static string GenerateGenreFilter(IEnumerable<string> genres)
 {
     var genreFilter = genres.Aggregate(String.Empty,
         (current, genre) => current + String.Format(SparqlResources.ContainsPattern, genre.ToLower()));
     genreFilter = genreFilter.Substring(0, genreFilter.LastIndexOf("||", StringComparison.Ordinal));
     return genreFilter;
 }
开发者ID:catalin-,项目名称:muxar,代码行数:7,代码来源:DbpediaHelper.cs


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