本文整理汇总了C#中ICollection.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Sum方法的具体用法?C# ICollection.Sum怎么用?C# ICollection.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.Sum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OverallScore
public OverallScore(ICollection<CpScore> cpScores, CpScore latestCpScore, int latestCp)
{
_cps = cpScores.Count;
EnlightenedScoreTotal = cpScores.Sum(item => item.EnlightenedScore);
ResistanceScoreTotal = cpScores.Sum(item => item.ResistanceScore);
LastCpScore = latestCpScore;
LastCp = latestCp;
}
示例2: TimingStatSummary
public TimingStatSummary(ICollection<TimingStat> stats, DateTime start, DateTime end) {
Stats = stats;
Count = Stats.Sum(s => s.Count);
MinDuration = Stats.Min(s => s.MinDuration);
MaxDuration = Stats.Max(s => s.MaxDuration);
TotalDuration = Stats.Sum(s => s.TotalDuration);
AverageDuration = Count > 0 ? (double)TotalDuration / Count : 0;
StartTime = start;
EndTime = end;
}
示例3: GaugeStatSummary
public GaugeStatSummary(ICollection<GaugeStat> stats, DateTime start, DateTime end) {
Stats = stats;
Count = Stats.Sum(s => s.Count);
Total = Stats.Sum(s => s.Total);
Last = Stats.Last().Last;
Min = Stats.Min(s => s.Min);
Max = Stats.Max(s => s.Max);
StartTime = start;
EndTime = end;
Average = Count > 0 ? Total / Count : 0;
}
示例4: GetQuote
public QuoteCalculationResult GetQuote(int loanAmount, ICollection<Offer> offers)
{
if (null == offers)
{
throw new ArgumentNullException(nameof(offers));
}
if (offers.Sum(x => x.CashAvailable) < loanAmount)
{
return null;
}
var totalRepayment = CalculateTotalToPay(loanAmount, offers);
var quote = (totalRepayment - loanAmount) / loanAmount;
var monthlyRepayment = loanAmount * (1 + quote) / LoanLengthInMonths;
return new QuoteCalculationResult
{
LoanAmount = loanAmount,
Quote = quote,
MonthlyRepayment = monthlyRepayment,
TotalRepayment = totalRepayment
};
}
示例5: StdDev
private double StdDev(ICollection<double> vals)
{
double sum = vals.Sum();
double avg = sum / vals.Count;
double sumSquaredError = 0;
foreach (double x in vals)
sumSquaredError += (x - avg) * (x - avg);
return Math.Sqrt(sumSquaredError / vals.Count);
}
示例6: Reload
public void Reload()
{
var doc = new XmlDocument();
doc.Load("/res/gutter.xml".AsAbsolute());
elements = doc.SelectNodes("/gutter/element[@visible=\"true\"]").Cast<XmlElement>()
.Select(x => (IGutterElement)Assembly.GetExecutingAssembly().CreateInstance(x.GetAttribute("class")))
.ToList();
Width = elements.Sum(x => x.Width);
}
示例7: BuildMany
public static SuffixArray BuildMany(ICollection<Nucleotide[]> fragments)
{
var tmp = new byte[fragments.Count + fragments.Sum(p => p.Length)];
int i = 0;
foreach (var fragment in fragments)
{
foreach (var nucleotide in fragment)
tmp[i++] = (byte) nucleotide;
tmp[i++] = (byte)Nucleotide.End;
}
tmp[i - 1]++;
var sfx = new SuffixArray(tmp);
return sfx;
}
示例8: BuildMany2
public static TextComparer BuildMany2(ICollection<Nucleotide[]> fragments, int minGroupSize = 0)
{
var tmp = new byte[fragments.Count + fragments.Sum(p => p.Length)];
int i = 0;
foreach (var fragment in fragments)
{
foreach (var nucleotide in fragment)
tmp[i++] = (byte)nucleotide;
tmp[i++] = (byte)Nucleotide.End;
}
tmp[i - 1]++;
var sfx = new SuffixArray(tmp, minGroupSize);
return new TextComparer(tmp, sfx);
}
示例9: RequeryIfRequired
private IEnumerable<LocationGroup> RequeryIfRequired(ICollection<LocationGroup> results, string addressQuery, ILocationGroupingStrategy groupingStrategy)
{
var locationsSum = results.Sum(g => g.LocationsCount);
if (!results.Any() || locationsSum == 0)
return results;
if (results.HasSingleGroup() || locationsSum < GROUPING_THRESHOLD) {
var groupingStrategyBuilder = new LocationGroupingStrategyBuilder(_locationQueryFields.PrimaryText)
.ThenBy(_locationQueryFields.SecondaryText)
.ThenBy(_locationQueryFields.HouseNumber)
.ThenBy(groupingStrategy);
return _groupRepository.FindGroupedLocations(addressQuery, groupingStrategyBuilder.Build());
}
return results;
}
示例10: ConsumptionSummary
public ConsumptionSummary(ICollection<ConsumptionItem> consumptionItems)
{
Total = consumptionItems.Count;
TotalCost = consumptionItems.Sum(c => c.Cost);
consumptionItems.ToList().ForEach(c =>
{
var user = c.Consumer as User;
if (c.Status == ValueObject.ItemStatus.Done)
{
PaidUsers.Add(user);
PaidCost += c.Cost;
}
else
{
UnpaidUsers.Add(user);
UnpaidCost += c.Cost;
}
});
}
示例11: Append
public Task<AppendResult> Append(string stream, ICollection<Message> data) {
stream = stream.ToLowerInvariant();
var hash = stream.GetHashCode();
var segment = Get(stream);
return _scheduler.StartNew(hash, () => {
using (Metrics.StartTimer("storage.append.time")) {
var append = segment.Append(data);
Metrics.Counter("storage.append.events", data.Count);
Metrics.Counter("storage.append.bytes", data.Sum(mw => mw.Value.Length));
// current position of a stream
Metrics.Gauge("stream." + stream, append.Position);
// number of appends to a stream
Metrics.Counter("stream." + stream + ".append.ok");
Metrics.Counter("stream." + stream + ".append.events", data.Count);
return append;
}
});
}
示例12: CanCloseTheGame
public bool CanCloseTheGame(PlayerTurnContext context, ICollection<Card> playerCards)
{
// Stalker has A and 10 from trumps, certain ammount of points and some other winning cards.
var hasHighTrumps = this.cardHolder.AllCards[context.TrumpCard.Suit][CardType.Ace] == CardStatus.InStalker &&
this.cardHolder.AllCards[context.TrumpCard.Suit][CardType.Ten] == CardStatus.InStalker;
// Stalker has 40 and is already above certain points.
var has40 = this.cardHolder.AllCards[context.TrumpCard.Suit][CardType.King] == CardStatus.InStalker
&& this.cardHolder.AllCards[context.TrumpCard.Suit][CardType.Queen] == CardStatus.InStalker;
var hasEnoughAfterAnounce = context.FirstPlayerRoundPoints > StalkerHelperConstants.CloseGamePointsBeforeAnnounce;
var hasNecessaryPoints = playerCards.Sum(c => c.GetValue()) + context.FirstPlayerRoundPoints > StalkerHelperConstants.CloseGameMinimumPoints;
var sureWiningCards = playerCards.Count(card => !this.ContainsGreaterCardThan(card, CardStatus.InDeckOrEnemy));
if (has40 && hasEnoughAfterAnounce)
{
return true;
}
return hasHighTrumps && hasNecessaryPoints && sureWiningCards > 0;
}
示例13: CombineByte
protected static byte[] CombineByte(ICollection<byte[]> buffers)
{
Int32 length = buffers.Sum(tempbyte => tempbyte.Length);
Byte[] result = new Byte[length];
Int32 offset = 0;
foreach (byte[] buffer in buffers)
{
Buffer.BlockCopy(buffer, 0, result, offset, buffer.Length);
offset += buffer.Length;
}
return result;
}
示例14: AddRow
private void AddRow(ICollection<IControl> controls, ICollection<int> percentWidths, double y)
{
if (controls.Count != percentWidths.Count)
{
throw new ArgumentException("Control count have to be equal to percentWidths count");
}
if (percentWidths.Sum() != 100)
{
throw new ArgumentException("Percents sum have to be 100");
}
double left = 0;
double maxWidth = Rect.Width - MarginLeft - MarginRight;
var controlWidthPairs = controls.Zip(percentWidths, (c, p) => new {Control = c, PercentWidth = p});
foreach (var pair in controlWidthPairs)
{
double x = left;
double width = maxWidth*pair.PercentWidth/100;
double height = pair.Control.Rect.Height;
pair.Control.Rect = new XRect(x, y, width, height);
left += width;
Controls.Add(pair.Control);
}
_currentY = controls.Select(x => (x.Rect.Height + x.Rect.Y)).Max();
Rect = new XRect(Rect.X, Rect.Y, Rect.Width, _currentY + MarginTop + MarginBottom);
}
示例15: WritePathList
private void WritePathList(ICollection<string> pathList)
{
int pathSize = pathList.Sum(path => path.Length + 1); // + 1, as all strings are null terminated
int pathListSize = 8 + 8 * pathList.Count + pathSize;
archiveWriter.Write(pathListSize);
archiveWriter.Write(pathList.Count);
int current = 8 + pathList.Count * 8;
foreach (var path in pathList)
{
archiveWriter.Write(current);
archiveWriter.Write(path.Length + 1);
current += path.Length + 1; // +1, as all strings are null terminated
}
foreach (var path in pathList)
{
archiveWriter.WriteNullTerminatedString(path);
}
}