本文整理汇总了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;
}
示例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");
}
}
示例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);
}
示例4: CombineHashCodes
private static int CombineHashCodes(IEnumerable<object> objs)
{
unchecked
{
return objs.Aggregate(17, (current, obj) => current * 23 + (obj != null ? obj.GetHashCode() : 0));
}
}
示例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");
}
});
}
示例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;
}
示例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);
}
示例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();
}
示例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)) };
}
示例10: PrettyPrint
public static string PrettyPrint(IEnumerable<PositionInText> positions)
{
return positions.Aggregate(
"positions: ",
(res, next) => res + ", " + next.ToString()
);
}
示例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);
}
示例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");
}
}
示例13: GetGenericParamString
private static string GetGenericParamString(IEnumerable<string> typeParamString)
{
var genericParamString = typeParamString
.Aggregate("", (s, i) => string.Format("{0}{1},", s, i))
.TrimEnd(',');
return genericParamString;
}
示例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();
}
示例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;
}