本文整理汇总了C#中ICollection.Aggregate方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Aggregate方法的具体用法?C# ICollection.Aggregate怎么用?C# ICollection.Aggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.Aggregate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllTypesAsString
string GetAllTypesAsString(ICollection<string> types)
{
// This causes a conflict with the vim keyword 'contains'
types.Remove("Contains");
return types.Aggregate("", (current, type) => current + type + " ");
}
示例2: EvaluateList
public static string EvaluateList(ICollection<Object> collection, Object lowerNumber, Object higherNumber)
{
DivisionOutput result = collection.Aggregate(
new DivisionOutput() { Operations = String.Empty, Log = String.Empty },
(currentOutput, value) =>
currentOutput += EvaluateItem(value, lowerNumber, higherNumber));
return result.Operations + "\r\n" + result.Log;
}
示例3: Setup
public static string Setup(BackgroundWorker worker, ICollection<Row> rows, ICollection<Row> excludeRows, IEnumerable<string> list, IEnumerable<string> exclude)
{
foreach (var i in list)
{
if (worker.CancellationPending) return null;
if (exclude.Any(j => i.EndsWith(j, StringComparison.CurrentCultureIgnoreCase)))
{
excludeRows.Add(new Row(i, false));
}
else if (System.IO.Directory.Exists(i))
{
worker.ReportProgress(0, string.Format("{0:#,0}ファイル {1:#,0}行 {2:#,0}バイト 除外 {3:#,0}", rows.Count, rows.Aggregate(0L, (s, r) => s += r.Count ?? 0L), rows.Aggregate(0L, (s, r) => s += r.Size ?? 0L), excludeRows.Count));
if (Setup(worker, rows, excludeRows, System.IO.Directory.EnumerateFileSystemEntries(i), exclude) == null) return null;
}
else if (!rows.Any(j => j.Path == i))
{
rows.Add(new Row(i, true));
}
}
return string.Format("全 {0:#,0}ファイル {1:#,0}行 {2:#,0}バイト 除外 {3:#,0}", rows.Count, rows.Aggregate(0L, (s, r) => s += r.Count ?? 0L), rows.Aggregate(0L, (s, r) => s += r.Size ?? 0L), excludeRows.Count);
}
示例4: Parse
internal static string Parse(string content, List<string> matches, ICollection<PgType> types)
{
foreach (string match in matches)
{
string comment = HtmlHelper.RemoveComment(match);
if (!comment.StartsWith("Types"))
{
continue;
}
comment = comment.Replace("Types", "");
string items = "";
items = types.Aggregate(items, (current, type) => current + Parse(comment, type));
content = content.Replace(match, items);
}
return content;
}
示例5: TextureAtlas
public TextureAtlas(Device device, ICollection<string> filenames) {
NumCells = filenames.Count;
// Note: all textures need to be the same size
var tex = Texture2D.FromFile(device, filenames.First());
var w = tex.Description.Width;
var h = tex.Description.Height;
tex.Dispose();
Columns = Math.Min(8192 / w, (int)Math.Ceiling(Math.Sqrt(NumCells)));
Rows = Math.Min(8192 / h, (int)Math.Ceiling((float)NumCells/Columns));
System.Diagnostics.Debug.Assert(Columns * Rows >= NumCells);
var bitmap = new Bitmap(Columns * w, Rows * h);
_texTransforms = new Matrix[NumCells];
using (var g = Graphics.FromImage(bitmap)) {
g.Clear(Color.Black);
var r = 0;
var c = 0;
foreach (var filename in filenames) {
g.DrawImage(new Bitmap(filename), new Point(c*w, r*h) );
_texTransforms[r * Columns + c] =
Matrix.Scaling(1.0f/(Columns*2), 1.0f / (2*Rows), 0) *
Matrix.Translation(c * w / (float)bitmap.Width, r * h / (float)bitmap.Width, 0);
c++;
if (c >= Columns) {
c = 0;
r++;
}
}
}
var tmpFile = Path.GetTempFileName() + ".bmp";
bitmap.Save(tmpFile);
TextureView = ShaderResourceView.FromFile(device, tmpFile);
TextureView.Resource.DebugName = "texture atlas: " +filenames.Aggregate((i, j) => i + ", " + j);
}
示例6: DataTableToCSV
/// <summary>
/// 导出到CSV文件
/// </summary>
/// <param name="titles">文件标题</param>
/// <param name="datas">数据</param>
/// <param name="fileName">要保存的文件名</param>
public static void DataTableToCSV(ICollection<string> titles, IEnumerable<object[]> datas, string fileName,
char split = ',', Encoding encoding = null)
{
if (encoding == null)
encoding = Encoding.UTF8;
var fs = new FileStream(fileName, FileMode.OpenOrCreate);
var sw = new StreamWriter(new BufferedStream(fs), encoding);
var title = titles.Aggregate("", (current, title1) => current + (title1 + split));
title = title.Substring(0, title.Length - 1) + "\n";
sw.Write(title);
foreach (var rows in datas)
{
var line = new StringBuilder();
foreach (var row in rows)
{
if (row != null)
{
line.Append(row.ToString().Trim());
}
else
{
line.Append(" ");
}
line.Append(split);
}
var result = line.ToString().Substring(0, line.Length - 1) + "\n";
sw.Write(result);
}
sw.Close();
fs.Close();
}
示例7: GetWebsiteNameForGoCommand
/// <summary>
/// this method will acquire the website name from a given command which has been identified
/// as a go to website command.
/// </summary>
/// <param name="commandSegments">command segments as a list (to remove problems that may occur when there are spaces)</param>
/// <returns>identified website name</returns>
public static string GetWebsiteNameForGoCommand(ICollection<string> commandSegments)
{
try
{
var fileContent = FileManager.GetContentOfAFile("fnc_brwsr_go"); // get the contents of the respective file as a list
// the file content above do not comprise of the website names
// thus the underneath foreach loop will iterate through the file content
// and if the any of the content is available in the command segments, it will remove them
// so that the website name will be remaining at the end
foreach (var content in fileContent.Where(commandSegments.Contains))
{
commandSegments.Remove(content);
}
// from the remaining command segment, if the user has provided the command as
// for instance google dot com, the "dot" will be replaced by a "." and finally the command
// segments will be concatenated and returned to the user
return commandSegments.Aggregate("", (current, segment) => current + (segment == "dot" ? "." : segment));
}
catch (Exception ex)
{
Log.ErrorLog(ex);
throw;
}
}
示例8: GetCategories
static string GetCategories(ICollection<Category> categories)
{
if (categories == null || categories.Count == 0)
return string.Empty;
var html = categories.Aggregate("", (current, cat) => current + string.Format("<a href='#' onclick=\"ChangePostFilter('Category','{0}','{1}')\">{1}</a>, ", cat.Id, cat.Title));
return html.Trim().Substring(0, html.Trim().Length - 1);
}
示例9: AppendLine
private static double AppendLine(PageRenderData context, ICollection<TextElement> inlines, TextAlignment align,
ParagraphInfo p, double width, double top, double defaultFontSize,
int paragraphID, bool firstLine)
{
if (inlines.Count == 0)
return top;
double height = inlines.Max((t => t.Height));
double inlinesWidth = inlines.Sum((t => t.Width));
double leftMargin = 0.0;
double wordSpacing = 0.0;
double textIndent = !firstLine || align != TextAlignment.Justify && align != TextAlignment.Left
? 0.0
: p.TextIndent;
width -= p.MarginRight + p.MarginLeft + textIndent;
switch (align)
{
case TextAlignment.Center:
leftMargin = (width - inlinesWidth)/2.0;
break;
case TextAlignment.Right:
leftMargin = width - inlinesWidth;
break;
case TextAlignment.Justify:
wordSpacing = (width - inlinesWidth)/(inlines.Count - 1);
break;
}
double tempLeftMargin = leftMargin + (p.MarginLeft + textIndent);
inlines.Aggregate(tempLeftMargin, (current, inlineItem) =>
BuildInlineItem(context, top, defaultFontSize, paragraphID, inlineItem, height, current, wordSpacing));
return top + height * AppSettings.Default.FontSettings.FontInterval;
}
示例10: GetSummaryReport
public static string GetSummaryReport(ICollection<SessionEx> sessions)
{
var res = new StringBuilder(DefaultBufferSize);
res.AppendLine("Name\tValue");
if (sessions.Count > 0)
{
var minDate = sessions.Min(session => session.LastUpdateTime);
res.AppendLine("MinDate\t{0}", minDate.ToString("yyyy-MM-dd HH:mm:ss"));
var maxDate = sessions.Max(session => session.LastUpdateTime);
res.AppendLine("MaxDate\t{0}", maxDate.ToString("yyyy-MM-dd HH:mm:ss"));
}
// append leading space as a workaround for the PowerPivot quirk
// http://social.msdn.microsoft.com/Forums/en-US/sqlkjpowerpivotforexcel/thread/456699ec-b5a2-4ae9-bc9f-b7ed2d637959
res.AppendLine("SessionsCount\t {0}", sessions.Count);
var latencyRecordsCount = sessions.Aggregate(0,
(val, session) => val + session.Records.Where(Util.IsLatency).Count());
res.AppendLine("LatencyRecordsCount\t {0}", latencyRecordsCount);
var jitterRecordsCount = sessions.Aggregate(0,
(val, session) => val + session.Records.Where(Util.IsJitter).Count());
res.AppendLine("JitterRecordsCount\t {0}", jitterRecordsCount);
return res.ToString();
}
示例11: UpdateSummaryInformation
/// <summary>
/// Updates information in summary page.
/// </summary>
/// <param name="remappingList">List of remappings</param>
private void UpdateSummaryInformation(ICollection<RemappingResult> remappingList)
{
TimeSpan baseDuration = m_plan.GetTotalTime(m_character.After(m_plan.ChosenImplantSet), false);
lvPoints.Items.Clear();
// Add global informations
ListViewGroup globalGroup = new ListViewGroup("Global informations");
lvPoints.Groups.Add(globalGroup);
TimeSpan savedTime = remappingList.Aggregate(TimeSpan.Zero,
(current, remap) =>
current.Add(remap.BaseDuration.Subtract(remap.BestDuration)));
lvPoints.Items.Add(new ListViewItem(
$"Current time : {baseDuration.ToDescriptiveText(DescriptiveTextOptions.IncludeCommas)}", globalGroup));
if (savedTime != TimeSpan.Zero)
{
lvPoints.Items.Add(
new ListViewItem(
$"Optimized time : {baseDuration.Subtract(savedTime).ToDescriptiveText(DescriptiveTextOptions.IncludeCommas)}",
globalGroup));
if (savedTime < TimeSpan.Zero)
{
ListViewItem savedTimeItem = lvPoints.Items.Add(
new ListViewItem(
$"{(-savedTime).ToDescriptiveText(DescriptiveTextOptions.IncludeCommas)} slower than current.",
globalGroup));
savedTimeItem.ForeColor = Color.DarkRed;
}
else
{
ListViewItem savedTimeItem = lvPoints.Items.Add(
new ListViewItem(
$"{savedTime.ToDescriptiveText(DescriptiveTextOptions.IncludeCommas)} better than current.",
globalGroup));
savedTimeItem.ForeColor = Color.DarkGreen;
}
}
else
lvPoints.Items.Add(new ListViewItem("Your attributes are already optimal.", globalGroup));
// Notify plan updated
ListViewItem lvi = new ListViewItem("Your plan has been updated.", globalGroup)
{ Font = FontFactory.GetFont(lvPoints.Font, FontStyle.Bold) };
lvPoints.Items.Add(lvi);
// Add pages and summary informations
TimeSpan lastRemap = TimeSpan.Zero;
foreach (RemappingResult remap in remappingList)
{
AddSummaryForRemapping(remap, ref lastRemap);
}
columnHeader.Width = lvPoints.ClientSize.Width;
}
示例12: GetClosestLocation
private Location GetClosestLocation(ICollection<Location> locations, Location location)
{
return locations.Aggregate((loc1, loc2) => location.ComputeEuclidicDistance(loc1) < location.ComputeEuclidicDistance(loc2) ? loc1 : loc2);
}
示例13: Optimize
public void Optimize(
BigInteger allFeatureBitMask, BigInteger rejectingFeatureBitMask,
ICollection<BigInteger> rejectedFeatures) {
Accepting &= allFeatureBitMask
^ rejectedFeatures.Aggregate(rejectingFeatureBitMask, (a, b) => a | b);
}
示例14: DeduceType
public static Type DeduceType(ICollection<object> values)
{
// Try to find a common type among the elements.
var result = values.Aggregate(null as Type,
(current, next) => GetCommonType(current, next != null ? next.GetType() : typeof(object)));
if (result == typeof(object))
{
// Try again with interfaces.
var interfaceSets = values.Select(item => item != null ? item.GetType().GetInterfaces() : null);
foreach (var commonInterface in CommonInterfaces)
{
if (interfaceSets.All(interfaceSet =>
interfaceSet == null || interfaceSet.Contains(commonInterface)))
{
result = commonInterface;
break;
}
}
}
return result ?? typeof(object);
}
示例15: GetTags
static string GetTags(ICollection<string> tags)
{
if (tags == null || tags.Count == 0)
return string.Empty;
var html = tags.Aggregate("", (current, tag) => current + string.Format("<a href='#' onclick=\"ChangePostFilter('Tag','{0}','')\">{0}</a>, ", tag));
return html.Trim().Substring(0, html.Trim().Length - 1);
}