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


C# this.Aggregate方法代码示例

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


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

示例1: Quickhull

        /// <summary>
        /// Given a set of points, performs the quickhull algorithm on them to determine a convex set
        /// </summary>
        /// <param name="points">An unordered set of points in 2D space</param>
        /// <returns>The points in order of the convex hull</returns>
        public static IEnumerable<Vector2> Quickhull(this IEnumerable<Vector2> points)
        {
            Vector2 min = points.Aggregate((a, b) => a.X < b.X ? a : b);
            Vector2 max = points.Aggregate((a, b) => a.X > b.X ? a : b);
            Vector2 dir = Vector2.Normalize(max - min);

            List<Vector2> above = new List<Vector2>();
            List<Vector2> below = new List<Vector2>();
            foreach (var point in points)
            {
                if (point == min || point == max)
                    continue;

                if (IsLeftOfLine(point, min, dir))
                    above.Add(point);
                else
                    below.Add(point);
            }

            yield return min;

            foreach (var point in Quickhull(above, min, dir, max))
                yield return point;

            yield return max;

            foreach (var point in Quickhull(below, min, dir, max))
                yield return point;
        }
开发者ID:martindevans,项目名称:csg.js,代码行数:34,代码来源:ConvexHullExtensions.cs

示例2: Merge

        public static string Merge(this IEnumerable< string> strings, string separator)
        {
#if NET4
            Contract.Requires(strings!= null);
#else
			if (strings == null) throw new ArgumentNullException("strings");
#endif
            if (separator == null)
                return strings.Aggregate(new StringBuilder(), (x, y) => x.Append(y)).ToString();
            var stringBuilder = strings.Aggregate(new StringBuilder(), (x, y) => x.Append(y).Append(separator));
            return (stringBuilder.Length >= separator.Length)
                       ? stringBuilder.ToString(0, stringBuilder.Length - separator.Length)
                       : stringBuilder.ToString();

        }
开发者ID:xcrash,项目名称:Yandex-Direct.NET,代码行数:15,代码来源:Extensions.cs

示例3: Variance

 public static float Variance(this IEnumerable<float> source)
 {
     float avg = source.Average();
     float d = source.Aggregate(0.0f,
                                (total, next) => total + (float) Math.Pow(next - avg, 2));
     return d/(source.Count() - 1);
 }
开发者ID:idaohang,项目名称:Helicopter-Autopilot-Simulator,代码行数:7,代码来源:LinqExtensions.cs

示例4: AggregateAppend

 public static string AggregateAppend(this IEnumerable<string> strings, bool newLine)
 {
     return
         strings.Aggregate(new StringBuilder(),
             (builder, next) => newLine ? builder.AppendLine(next) : builder.AppendFormat("{0} ", next))
             .ToString();
 }
开发者ID:JonGonard,项目名称:ShlugaBuilder,代码行数:7,代码来源:StringsHelper.cs

示例5: Sum

        public static BigInteger Sum(this IEnumerable<BigInteger> source)
        {
            if (source == null)
                throw new ArgumentNullException(("source"));

            return source.Aggregate<BigInteger, BigInteger>(0, (a, x) => a + x);
        }
开发者ID:raymonxo,项目名称:csharp,代码行数:7,代码来源:MathExtensions.cs

示例6: ToDiscordMessage

        public static string ToDiscordMessage(this IEnumerable<Command> commands)
        {
            var categoryNames = new List<string>();
            var categories = new List<Category>();

            categoryNames.AddRange(commands.Aggregate(new List<string>(), (accumulated, next) =>
                    {
                        accumulated.Add(next.Category);
                        return accumulated;
                    }));

            categories.AddRange(categoryNames.Distinct().Aggregate(new List<Category>(), (accumulated, next) =>
                    {
                        accumulated.Add(new Category
                            { 
                                Name = next, 
                                Commands = commands.Where(c => c.Category == next).ToList()
                            });

                        return accumulated;
                    }));

            
            var buffer = "Here is a list of available commands you can use to interact with me:\n\n";
            foreach (var category in categories)
            {
                buffer += string.Format("**{0}**\n\n", category.Name);
                foreach (var command in category.Commands)
                {
                    buffer += string.Format("**!{0}** {1} - {2}\n", command.Text, string.Concat(command.Parameters.Select(r => string.Format("**[{0}]** ", r.Name))), command.Description);
                }
                buffer += "\n";
            }
            return buffer;
        }
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:35,代码来源:CommandHelper.cs

示例7: GreatestCommonDenominator

        /// <summary>
        /// Gets the greatest common denominator of all the integers in the source collection.
        /// </summary>
        /// <param name="source">The collection of integers.</param>
        /// <returns>The greatest common denominator.</returns>
        public static int GreatestCommonDenominator(this IEnumerable<int> source)
        {
            if ((object)source == null)
                throw new ArgumentNullException("source", "source is null");

            return source.Aggregate(GreatestCommonDenominator);
        }
开发者ID:rmc00,项目名称:gsf,代码行数:12,代码来源:Euclidean.cs

示例8: Hash

 public static int Hash(this byte[] buffer)
 {
     unchecked
     {
         return buffer.Aggregate(0, (current, b) => (current * 31) ^ b);
     }
 }
开发者ID:stsimonas,项目名称:BnBEditor,代码行数:7,代码来源:BufferManipulation.cs

示例9: Flatten

 public static string Flatten(this IEnumerable<string> list, string separator)
 {
     if (list == null) throw new ArgumentNullException("list");
     if (separator == null) throw new ArgumentNullException("separator");
     string result = list.Aggregate(String.Empty, (acc, next) => acc + next + separator);
     return result.Left(result.Length - separator.Length);
 }
开发者ID:LazyAbstract,项目名称:AReportes,代码行数:7,代码来源:StringExtensions.cs

示例10: AppendStrings

 public static string AppendStrings(this IEnumerable<string> list, string seperator = ", ")
 {
     return list.Aggregate(
         new StringBuilder(),
         (sb, s) => (sb.Length == 0 ? sb : sb.Append(seperator)).Append(s),
         sb => sb.ToString());
 }
开发者ID:holer-h,项目名称:Dapper-Extensions,代码行数:7,代码来源:ReflectionHelper.cs

示例11: Center

        // Get center of path
        public static Vector2 Center(this List<Vector2> points)
        {
            Vector2 result = points.Aggregate(Vector2.Zero, (current, point) => current + point);

            result /= points.Count;

            return result;
        }
开发者ID:dtx,项目名称:KMPC,代码行数:9,代码来源:GoldenSectionExtensions.cs

示例12: GetHtmlTable

        public static string GetHtmlTable(this List<Guest> guests)
        {
            var table = guests.Aggregate("<table>", (current, guest) => current + string.Format("<tr><td>{0}</td><td>{1}</td></tr>", guest.UserName, guest.Message));

            table += "</table>";

            return table;
        }
开发者ID:EventPromo,项目名称:HttpServer,代码行数:8,代码来源:Extension.cs

示例13: BuildQueryString

 public static string BuildQueryString(this IDictionary<string, string> qry)
 {
     if (qry == null) return string.Empty;
     if (qry.Count < 1)
         return string.Empty;
     var str = qry.Aggregate("?", (current, pair) => current + pair.Key + "=" + Uri.EscapeDataString(pair.Value) + "&");
     return str.Remove(str.Length - 1);
 }
开发者ID:aloker,项目名称:Caliburn.Micro.Autofac,代码行数:8,代码来源:BuildUriExtensions.cs

示例14: Implode

        public static string Implode(this IEnumerable<string> array, string glue)
        {
            var result = array.Aggregate(string.Empty, (current, element) => current + (glue + element));

            if (result.Length > glue.Length)
                result = result.Substring(glue.Length);

            return result;
        }
开发者ID:burkhartt,项目名称:L2R,代码行数:9,代码来源:ArrayHelpers.cs

示例15: AreNullOrBlank

        public static bool AreNullOrBlank(this IEnumerable<string> values)
        {
            if (values.Count() == 0 || values == null)
            {
                return false;
            }

            return values.Aggregate(true, (current, value) => current & value.IsNullOrBlank());
        }
开发者ID:nadeemmar,项目名称:tweetsharp,代码行数:9,代码来源:StringExtensions.cs


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