本文整理汇总了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;
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例8: Hash
public static int Hash(this byte[] buffer)
{
unchecked
{
return buffer.Aggregate(0, (current, b) => (current * 31) ^ b);
}
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}