本文整理汇总了C#中IEnumerable.Max方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.Max方法的具体用法?C# IEnumerable.Max怎么用?C# IEnumerable.Max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.Max方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteHistory
internal static void WriteHistory(IEnumerable<IEvent> history, RoomieCommandInterpreter interpreter)
{
var headers = new[] {"Time Stamp", "Entity", "Type", "Source", ""};
var tableBuilder = new TextTable(new int[]
{
Math.Max(history.Max(x => x.TimeStamp.ToLocalTime().ToString().Length), headers[0].Length),
Math.Max(history.Max(x => ((x.Entity == null || x.Entity.Name == null) ? string.Empty : x.Entity.Name).Length), headers[1].Length),
Math.Max(history.Max(x => ((x.Type == null) ? string.Empty : x.Type.Name).Length), headers[2].Length),
Math.Max(history.Max(x => ((x.Source == null || x.Source.Name == null) ? string.Empty : x.Source.Name).Length), headers[3].Length),
ExtraLength(history)
});
interpreter.WriteEvent(tableBuilder.StartOfTable(headers));
foreach (var @event in history)
{
var extra = GetExtra(@event);
var line = tableBuilder.ContentLine(
@event.TimeStamp.ToLocalTime().ToString(),
(@event.Entity == null) ? string.Empty : @event.Entity.Name,
(@event.Type == null) ? string.Empty : @event.Type.Name,
(@event.Source == null) ? string.Empty : @event.Source.Name,
extra
);
interpreter.WriteEvent(line);
}
interpreter.WriteEvent(tableBuilder.EndOfTable());
}
示例2: ChunkIsStable
protected bool ChunkIsStable(IEnumerable<Zipping.Pair<int, int>> points)
{
const int maxVariance = 50;
var xVariance = points.Max(p => p.First) - points.Min(p => p.First);
var yVariance = points.Max(p => p.Second) - points.Min(p => p.Second);
return xVariance < maxVariance && yVariance < maxVariance;
}
示例3: ChunkIsStable
protected bool ChunkIsStable(IEnumerable<Point> points)
{
const int maxVariance = 50;
var xVariance = points.Max(p => p.X) - points.Min(p => p.Y);
var yVariance = points.Max(p => p.X) - points.Min(p => p.Y);
return xVariance < maxVariance && yVariance < maxVariance;
}
示例4: MinimumOf
public static BoundingBox MinimumOf(IEnumerable<BoundingBox> boxes)
{
decimal northmost = boxes.Max(b => b.North);
decimal southmost = boxes.Min(b => b.South);
decimal eastmost = boxes.Max(b => b.East);
decimal westmost = boxes.Min(b => b.West);
return new BoundingBox { North = northmost, South = southmost, East = eastmost, West = westmost };
}
示例5: SlidingBlockType
public SlidingBlockType(IEnumerable<Point> subBlocks, int typeID)
{
SubBlocks = new ObservableCollection<Point>(subBlocks);
if (subBlocks.Any()) // If sequence is not empty
{
SizeX = subBlocks.Max(t => t.X) + 1;
SizeY = subBlocks.Max(t => t.Y) + 1;
TypeID = typeID;
}
}
示例6: Overlay
public static Bitmap Overlay(IEnumerable<Bitmap> bmps, Bitmap.Config config = null)
{
int width = bmps.Max<Bitmap>(x => x.Width);
int height = bmps.Max<Bitmap>(x => x.Height);
Bitmap bmOverlay = Bitmap.CreateBitmap(width, height, config == null ? Bitmap.Config.Argb8888 : config);
Canvas canvas = new Canvas(bmOverlay);
foreach (var bmp in bmps)
canvas.DrawBitmap(bmp, 0, 0, null);
canvas.Dispose();
return bmOverlay;
}
示例7: SetPlotModelAxes
public void SetPlotModelAxes(
IEnumerable<DataPoint> seriesPoints,
string xAxisTitle, string yAxisTitle)
{
double minXVal = seriesPoints.Min<DataPoint>(dp => dp.X);
double maxXVal = seriesPoints.Max<DataPoint>(dp => dp.X);
double minYVal = seriesPoints.Min<DataPoint>(dp => dp.Y);
double maxYVal = seriesPoints.Max<DataPoint>(dp => dp.Y);
PlotType = PlotType.XY;
SetXAxisForPlotModel(minXVal, maxXVal, xAxisTitle);
SetYAxisForPlotModel(minYVal, maxYVal, yAxisTitle);
}
示例8: OctreeLookup
public OctreeLookup(IEnumerable<float[]> points)
{
tree = new Octree(
points.Max(p => p[0]),
points.Min(p => p[0]),
points.Max(p => p[1]),
points.Min(p => p[1]),
points.Max(p => p[2]),
points.Min(p => p[2]),
points.Count());
foreach (var p in points)
tree.AddNode(p[0], p[1], p[2], p);
}
示例9: ApplyChanges
public void ApplyChanges(IEnumerable<Change> changeList)
{
// separate
var speakerChanges = changeList.Where(c => string.Compare("speaker", c.EntityType, StringComparison.OrdinalIgnoreCase) == 0).ToList();
var sessionChanges = changeList.Where(c => string.Compare("session", c.EntityType, StringComparison.OrdinalIgnoreCase) == 0).ToList();
var updateClientChangeset = false;
if (speakerChanges.Count > 0)
{
ApplySpeakerChanges(speakerChanges);
SpeakerRepository.Save();
updateClientChangeset = true;
}
if (sessionChanges.Count > 0)
{
ApplySessionChanges(sessionChanges);
SessionRepository.Save();
updateClientChangeset = true;
}
if (updateClientChangeset)
{
int changeSet = changeList.Max(c => c.Changeset);
UpdateClientChangesetToLatest(changeSet);
}
}
示例10: AscendData
public AscendData(IEnumerable<long> dataPoints, string planetName, bool failedAscends)
{
long highestPoint = dataPoints.Max();
this._heightPoints = dataPoints.ToList();
this._planetName = planetName;
this._areFailedAscends = failedAscends;
StringBuilder sb = new StringBuilder();
sb = sb.Append("http://chart.apis.google.com/chart?").Append("cht=lc&chs=500x500")
.Append("&chd=t:");
foreach(double dataPoint in _heightPoints)
{
sb = sb.Append(dataPoint.ToString("0.00")).Append(',');
}
sb.Replace(',', '&', sb.Length - 1, 1);
this._chartName = string.Format("{0} ascends from the planet {1}", this._areFailedAscends ? "Failed" : "Successful", this._planetName);
sb = sb.Append("chtt=").Append(HttpUtility.UrlEncode(this._chartName)).Append("&hAxis.title=Height from surface");
this._chartUrl = sb.ToString();
log.DebugFormat("Created new AscendData, url is '{0}'", this._chartUrl);
}
示例11: ShowCommandUsage
public void ShowCommandUsage(IEnumerable<Command> availableCommands, OptionSet optionSet)
{
var processName = Process.GetCurrentProcess().ProcessName;
var usagePreamble = String.Format("Usage: {0} ", processName);
var usagePattern = GenerateUsagePattern(optionSet);
new ConsoleFormatter(ConsoleWriter.Default).Write(
new ConsoleTable().AddRow(
new ConsoleCell(usagePreamble).WithWidth(usagePreamble.Length).WithPadding(0),
new ConsoleCell(usagePattern).WithPadding(0)));
var maximumCommandNameLength = availableCommands.Count() > 0 ? availableCommands.Max(c => c.Name.Length) : 0;
var commandTable = new ConsoleTable().
AddEmptyRow().AddRow(
new ConsoleCell("The available commands are:").WithPadding(0));
foreach (var command in availableCommands)
{
commandTable.AddRow(
new ConsoleCell(command.Name).WithWidth(maximumCommandNameLength),
new ConsoleCell(command.Description));
}
new ConsoleFormatter(ConsoleWriter.Default).Write(commandTable);
}
示例12: RefreshPlayerByList
private void RefreshPlayerByList(IEnumerable<PlayerInfo> players)
{
foreach (var player in players.ToList())
{
var playerViewModel = Players.FirstOrDefault(p => p.Index == player.Index);
if (playerViewModel == null)
{
Players.Add(new PlayersViewModel
{
Index = player.Index,
Name = player.Name,
Duration = player.Duration,
});
}
else
{
playerViewModel.Name = player.Name;
playerViewModel.Score = player.Score;
playerViewModel.Duration = player.Duration;
}
}
var maxIndex = players.Any() ? players.Max(p => p.Index) : 0;
var excessPlayers = Players.Where(ep => ep.Index > maxIndex);
foreach (var excessPlayer in excessPlayers.ToList())
{
Players.Remove(excessPlayer);
}
}
示例13: Determine_col_widths
int[] Determine_col_widths(IEnumerable<string[]> records) {
var colWidths = new List<int> ();
for (var i = 0; i < records.First ().Length; i++) {
colWidths.Add (records.Max(r => r[i].Length));
}
return colWidths.ToArray ();
}
示例14: RenderLegend
protected override void RenderLegend(GraphPane gp, IEnumerable<RequestDataResults> dataResults)
{
var hostName = new TextObj(dataResults.First().HostName, dataResults.Count() + 1, dataResults.Max(x => x.AverageResponseTime) * 1.1);
hostName.FontSpec.Fill.IsVisible = false;
hostName.FontSpec.Border.IsVisible = false;
hostName.FontSpec.FontColor = Color.Black;
hostName.FontSpec.Size = 7;
gp.GraphObjList.Add(hostName);
var date = new TextObj(DateTime.Now.ToString(), dataResults.Count() + 1, dataResults.Max(x => x.AverageResponseTime) * 1.05);
date.FontSpec.Fill.IsVisible = false;
date.FontSpec.Border.IsVisible = false;
date.FontSpec.FontColor = Color.Black;
date.FontSpec.Size = 7;
gp.GraphObjList.Add(date);
}
示例15: Calculate
public static VehicleStatisticsModel Calculate(IEnumerable<Model.FillupEntry> fillUps, bool includeFirst = true)
{
if (!fillUps.Any()) return new VehicleStatisticsModel();
var firstFillUp = fillUps.OrderBy(x => x.Date).FirstOrDefault();
double totalFuelCost = 0.0;
double totalUnits = 0.0;
double totalCost = 0.0;
int totalDistance = 0;
foreach (var fillUp in fillUps)
{
if (includeFirst || fillUp != firstFillUp)
{
totalFuelCost += fillUp.PricePerUnit*fillUp.TotalUnits;
totalUnits += fillUp.TotalUnits;
totalCost += fillUp.TotalCost;
totalDistance += fillUp.Distance ?? 0;
}
}
var odometer = fillUps.Max(x => x.Odometer);
var earliestEntryDate = fillUps.Min(x => x.Date).ToUniversalTime();
var today = DateTime.UtcNow.Date;
var totalMonths = CalculateDifferenceInMonths(earliestEntryDate.Date, today.Date);
return new VehicleStatisticsModel(totalFuelCost, totalUnits, totalCost, totalDistance, odometer, totalMonths);
}