本文整理汇总了C#中IDictionary.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.Sum方法的具体用法?C# IDictionary.Sum怎么用?C# IDictionary.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.Sum方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RosterAssignmentAnalyzer
public RosterAssignmentAnalyzer(IDictionary<PositionAbbreviation, RosterPosition> rosterPositions, ICollection<Player> availablePlayers)
{
if (availablePlayers.Count > rosterPositions.Sum(rp => rp.Value.Count))
{
throw new ArgumentException("There are more players than roster positions available.");
}
_rosterPositions = rosterPositions;
_availablePlayers = availablePlayers;
}
示例2: Value
public double Value(IDictionary<string, double> p1, IDictionary<string, double> p2)
{
double dot = 0;
string[] keys = p2.Keys.ToArray();
foreach (string key in keys)
if (p1.ContainsKey(key))
dot += Math.Sqrt(p1[key] * p2[key]);
return -dot / Math.Sqrt(p1.Sum(c => c.Value)) * Math.Sqrt(p2.Sum(c => c.Value));
}
示例3: GenerateReport
static void GenerateReport(IDictionary<Uri, long> dump, IDictionary<string, long> errors)
{
var totalCount = dump.Sum(pair => pair.Value);
var distinctCount = dump.Count;
var errorCount = errors.Sum(pair => pair.Value);
var top10 = dump.OrderByDescending(pair => pair.Value).Take(10).ToList();
var top10Errors = errors.OrderByDescending(pair => pair.Value).Take(10).ToList();
Console.Clear();
Console.WriteLine($"Total Count:\t\t{totalCount}");
Console.WriteLine($"Distinct Count:\t\t{distinctCount}");
Console.WriteLine($"Error Count:\t\t{errorCount}");
Console.WriteLine();
Console.WriteLine("Top 10:");
top10.ForEach(pair => Console.WriteLine($" ({pair.Value}) {pair.Key}"));Console.WriteLine();
Console.WriteLine("Top 10 Errors:");
top10Errors.ForEach(pair => Console.WriteLine($" ({pair.Value}) {pair.Key}"));
}
示例4: Genie
// ReSharper restore UnusedMember.Local
public Genie(IDictionary<string, AnswerStatistic> answerStatistics, int answeringChoicesCount)
{
this.answerStatistics = answerStatistics;
this.answeringChoicesCount = answeringChoicesCount;
answersGuessedCount = answerStatistics.Sum(s => s.Value.AnswerCount);
questionStatistics = answerStatistics.SelectMany(s => s.Value.AnsweredQuestionsById)
.GroupBy(p => p.Key)
.ToDictionary(g => g.Key, g => new QuestionStatistic
{
ChoicesFrequencies = g.Aggregate(new int[answeringChoicesCount], (curr, p) =>
{
for (int i = 0; i < answeringChoicesCount; i++)
{
curr[i] += p.Value.ChoicesFrequencies[i];
}
return curr;
})
});
}
示例5: getAlleleFreqs
private Dictionary<Allele, double> getAlleleFreqs(IDictionary<Genotype, int> genotypeCounts)
{
// Get the total count of Alleles
long totalPop = genotypeCounts.Sum(pair => (long)pair.Value);
long totalAlleles = 2 * totalPop;
// Get the count of each Allele (twice in homozygotes, once in heterozygotes)
Dictionary<Allele, long> alleleCounts = new Dictionary<Allele, long>();
Genotype[] genotypes = genotypeCounts.Keys.ToArray();
foreach (Genotype g in genotypes) {
int count = genotypeCounts[g];
// Increment the first Allele's count
if (alleleCounts.ContainsKey(g.Allele1))
alleleCounts[g.Allele1] += count;
else
alleleCounts.Add(g.Allele1, count);
// Increment the second Allele's count
if (alleleCounts.ContainsKey(g.Allele2))
alleleCounts[g.Allele2] += count;
else
alleleCounts.Add(g.Allele2, count);
}
// Divide by total to get Allele frequencies
Dictionary<Allele, double> alleleFreqs = alleleCounts.ToDictionary(
pair => pair.Key,
pair => (double)pair.Value / (double)totalAlleles
);
return alleleFreqs;
}
示例6: WriteHeader
private void WriteHeader(StreamWriter sw, IDictionary<File, string> files, TypeDefinition[] types)
{
var total = files.Sum(x => x.Key.Annotations.Length);
sw.WriteLine("<html>");
sw.WriteLine("<head>");
sw.WriteLine("<meta charset='utf-8' />");
sw.WriteLine("<title>Warning Report</title>");
sw.WriteLine("<link rel='stylesheet' type='text/css' href='report.css' />");
sw.WriteLine("</head><body><div class='container'>");
sw.WriteLine("<h1>Summary</h1>");
sw.WriteLine("<table class='overview'>");
sw.WriteLine("<colgroup>");
sw.WriteLine("<col width='160' />");
sw.WriteLine("<col />");
sw.WriteLine("</colgroup>");
sw.WriteLine("<tbody>");
sw.WriteLine("<tr><th>Generated on:</th><td>" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "</td></tr>");
WriteStats(sw, files, types, total);
sw.WriteLine("</tbody>");
sw.WriteLine("</table>");
sw.WriteLine("<h1>Files</h1>");
}
示例7: GetWordCount
private int GetWordCount(IDictionary<string, int> words)
{
return words.Sum(pair => pair.Value);
}
示例8: RecordRowCounts
/// <summary>
/// Writes total captured rowcounts to log and graphite
/// </summary>
private void RecordRowCounts(IDictionary<string, long> changesCaptured)
{
long total = changesCaptured.Sum(x => x.Value);
logger.Log("Total rowcount across all tables: " + total, LogLevel.Info);
string key = string.Format("db.mssql_changetracking_counters.RowCountsMaster.{0}.{1}", Config.Master.Replace('.', '_'), Config.MasterDB);
logger.Increment(key, total);
}