本文整理汇总了C#中List.Max方法的典型用法代码示例。如果您正苦于以下问题:C# List.Max方法的具体用法?C# List.Max怎么用?C# List.Max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Max方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: foreach
void IDumpableAsText.DumpAsText(TextWriter writer)
{
var pbag = new List<KeyValuePair<String, String>>();
Func<KeyValuePair<String, String>, String> fmt = kvp =>
{
var maxKey = pbag.Max(kvp1 => kvp1.Key.Length);
return String.Format(" {0} : {1}", kvp.Key.PadRight(maxKey), kvp.Value);
};
Action<String> fillPbag = s =>
{
foreach (var line in s.SplitLines().Skip(1).SkipLast(1))
{
var m = Regex.Match(line, "^(?<key>.*?):(?<value>.*)$");
var key = m.Result("${key}").Trim();
var value = m.Result("${value}").Trim();
pbag.Add(new KeyValuePair<String, String>(key, value));
}
};
writer.WriteLine("Device #{0} \"{1}\" (/pci:{2}/dev:{3})", Index, Name, PciBusId, PciDeviceId);
fillPbag(Simd.ToString());
fillPbag(Clock.ToString());
fillPbag(Memory.ToString());
fillPbag(Caps.ToString());
pbag.ForEach(kvp => writer.WriteLine(fmt(kvp)));
}
示例2: Main
static void Main(string[] args)
{
var players = new List<Player>();
var shaker = new DiceShaker();
for (var i = 0; i < 100; i++)
{
var player = Factory.CreatePlayer(shaker);
System.Console.WriteLine(string.Format("Player {0}:\r\nThrowing Power: {1}\r\nTAS: {2}:\r\nTAM: {3}",
i,
player.ThrowPower.GetValue<double>(),
player.ThrowAccuracyShort.GetValue<double>(),
player.ThrowAccuracyMid.GetValue<double>()));
players.Add(player);
}
var maxPotential = players.Select(w => w.GetPotential()).Max();
var bestPlayer = players.First(w => w.GetPotential() == maxPotential);
var maxMidAcc = players.Max(w => w.ThrowAccuracyMid.GetValue<double>());
bestPlayer = players.First(w => w.ThrowAccuracyMid.GetValue<double>() == maxMidAcc);
var maxShortAcc = players.Max(w => w.ThrowAccuracyShort.GetValue<double>());
bestPlayer = players.First(w => w.ThrowAccuracyShort.GetValue<double>() == maxShortAcc);
if (bestPlayer != null)
{
}
}
示例3: ShowSampleItems_Click
private void ShowSampleItems_Click(object sender, EventArgs e) {
// create some sample items;
MyMap.MapElements.Clear();
MyMap.Layers.Clear();
var bounds = new List<LocationRectangle>();
foreach (var area in DataManager.SampleAreas) {
var shape = new MapPolygon();
foreach (var parts in area.Split(' ').Select(cord => cord.Split(','))) {
shape.Path.Add(new GeoCoordinate(double.Parse(parts[1], ci), double.Parse(parts[0], ci)));
}
shape.StrokeThickness = 3;
shape.StrokeColor = Colors.Blue;
shape.FillColor = Color.FromArgb((byte)0x20, shape.StrokeColor.R, shape.StrokeColor.G, shape.StrokeColor.B);
bounds.Add(LocationRectangle.CreateBoundingRectangle(shape.Path));
MyMap.MapElements.Add(shape);
}
var rect = new LocationRectangle(bounds.Max(b => b.North), bounds.Min(b => b.West), bounds.Min(b => b.South), bounds.Max(b => b.East));
MyMap.SetView(rect);
// show all Items
var itemsLayer = new MapLayer();
foreach (var item in DataManager.SampleItems) {
DrawItem(item, "Ulm", itemsLayer);
}
MyMap.Layers.Add(itemsLayer);
}
示例4: ExtractOfMaxNumbers
private static int[] ExtractOfMaxNumbers(List<int> list, int k)
{
List<int> maxNumbers = new List<int>();
for (int i = 0; i < k; i++)
{
maxNumbers.Add(list.Max());
list.Remove(list.Max());
}
return maxNumbers.ToArray();
}
示例5: Main
static void Main()
{
string input = Console.ReadLine();
List<decimal> inputNums = new List<decimal>();
List<decimal> oddNums = new List<decimal>();
List<decimal> evenNums = new List<decimal>();
string[] numbers = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var num in numbers)
{
inputNums.Add(decimal.Parse(num));
}
int index = 1;
for (int i = 0; i < inputNums.Count; i++)
{
if (index % 2 == 1)
{
oddNums.Add(inputNums[i]);
}
else
{
evenNums.Add(inputNums[i]);
}
index++;
}
if (inputNums.Count == 0)
{
Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
}
else if (inputNums.Count == 1)
{
double oddNumsSum = (double)oddNums.Sum();
double oddNumsMin = (double)oddNums.Min();
double oddNumsMax = (double)oddNums.Max();
Console.WriteLine("OddSum={0:G0}, OddMin={1:G0}, OddMax={2:G0}, EvenSum=No, EvenMin=No, EvenMax=No",
oddNumsSum, oddNumsMin, oddNumsMax);
}
else
{
double oddNumsSum = (double)oddNums.Sum();
double oddNumsMin = (double)oddNums.Min();
double oddNumsMax = (double)oddNums.Max();
double evenNumsSum = (double)evenNums.Sum();
double evenNumsMin = (double)evenNums.Min();
double evenNumsMax = (double)evenNums.Max();
Console.WriteLine("OddSum={0:G0}, OddMin={1:G0}, OddMax={2:G0}, EvenSum={3:G0}, EvenMin={4:G0}, EvenMax={5:G0}", // {...:G0} Remove trailing zeros
oddNumsSum, oddNumsMin, oddNumsMax, evenNumsSum, evenNumsMin, evenNumsMax);
}
}
示例6: CheckHorizontals
//this method checks the rows
private static string CheckHorizontals(string[,] theMatrix, int rows, int cols)
{
List<string> bestLine = new List<string>();
for (int row = 0; row < rows; row++)
{
string nextLine = string.Empty;
for (int col = 0; col < cols - 1; col++)
{
if (col == 0)
{
nextLine += theMatrix[row, col] + ", ";
}
if (theMatrix[row, col + 1].Equals(theMatrix[row, col]))
{
nextLine += theMatrix[row, col + 1] + ", ";
}
}
bestLine.Add(nextLine);
}
if (bestLine.Count > 0)
{
return bestLine.Max().ToString().Substring(0, bestLine.Max().Length - 2);
}
else
{
return string.Empty;
}
}
示例7: BestCircularFarmLocation
public static Vector3 BestCircularFarmLocation(int radius, int range, int minMinions = 3)
{
var minions = EntityManager.MinionsAndMonsters.CombinedAttackable.Where(it => !it.IsDead && it.IsValidTarget(range));
if (minions.Any() && minions.Count() == 1) return default(Vector3);
var hitsperminion = new List<int>();
int hits = new int();
for (int i = 0; i < minions.Count(); i++)
{
hits = 1;
for (int j = 0; j < minions.Count(); j++)
{
if (j == i) continue;
if (minions.ElementAt(i).Distance(minions.ElementAt(j)) <= radius) hits++;
}
hitsperminion.Add(hits);
}
if (hitsperminion.Any() && hitsperminion.Max() > minMinions)
{
var pos = minions.ElementAt(hitsperminion.IndexOf(hitsperminion.Max())).ServerPosition;
return pos;
}
return default(Vector3);
}
示例8: DisplayWinner
private void DisplayWinner()
{
votes = new List<int>();
votes.Add(toyStoryCount);
votes.Add(starWarsCount);
votes.Add(avengersCount);
votes.Add(northCount);
Console.WriteLine("");
if (toyStoryCount == votes.Max())
{
Console.WriteLine("Toy Story wins with {0} votes", toyStoryCount);
}
else if (starWarsCount == votes.Max())
{
Console.WriteLine("Star Wars wins with {0} votes", starWarsCount);
}
else if (avengersCount == votes.Max())
{
Console.WriteLine("Avengers: Age of Ultron wins with {0} votes", avengersCount);
}
else if (northCount == votes.Max())
{
Console.WriteLine("North by Northwest wins with {0} votes", northCount);
}
else
{
Console.WriteLine("It's a tie");
}
}
示例9: Process
internal static void Process()
{
Console.WriteLine("Day 2");
int totPaper = 0;
int totRibbon = 0;
for (int i = 0; i < Day02.Input.Count; i++)
{
var inpLine = Day02.Input[i];
int len = int.Parse(inpLine.Split('x')[0]);
int width = int.Parse(inpLine.Split('x')[1]);
int height = int.Parse(inpLine.Split('x')[2]);
var lst = new List<int> { len, width, height };
var smallest = lst.FindAll(d => d < lst.Max());
if (smallest.Count == 1)
smallest.Add(lst.Max());
else if (smallest.Count == 0)
{
smallest.Add(lst.Max());
smallest.Add(lst.Max());
}
totPaper += (2 * len * width) + (2 * width * height) + (2 * height * len) + ((int)smallest[0] * (int)smallest[1]);
totRibbon += (2 * smallest[0]) + (2 * smallest[1]) + (len * width * height);
}
Console.WriteLine(" The elves should order " + totPaper + " sqft of wrapping-paper, and " + totRibbon + " feet of ribbon...");
}
示例10: Main
static void Main(string[] args)
{
int[] arr = new int[5]; // array to keep numbers from user
List<int> lista = new List<int>(); // list to keep all odd numbers from users numbers
Console.WriteLine("Values for the array:");
for (int i = 0; i < arr.Length; i++) // loop taking numbers from user
{
Console.Write("Value for index {0}:", i);
arr[i] = int.Parse(Console.ReadLine());
}
foreach (int x in arr) // loop adding all odd numbers(taken from arr[])
{ // to lista (doasn't working on page if not x!=1)
if (x % 2 != 0 & x != 1)
lista.Add(x);
}
for (int i = 0; i < arr.Length; i++) // if we meet zero in lista, loop is looking for a max odd number from lista
{ // and replace zero this number, next remove this number from lista
if (arr[i] == 0 & lista.Count > 0)
{
arr[i] = lista.Max();
lista.Remove(lista.Max());
}
}
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
}
示例11: GetLayoutPanel
private static TableLayoutPanel GetLayoutPanel(List<List<Control>> controls)
{
int columnCount = controls.Max(list => list.Count);
var layoutPanel = new TableLayoutPanel
{
ColumnCount = columnCount,
RowCount = controls.Count,
Dock = DockStyle.Fill,
Location = new Point(0, 0),
Name = "layoutPanel",
BorderStyle = BorderStyle.Fixed3D
};
int horizontalMargin = layoutPanel.Margin.Horizontal;
for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
{
int controlIndex = columnIndex;
bool columnExists = controls.Count - 1 >= columnIndex;
try
{
int columnWidth = !columnExists ? 0 : controls.Max(control => control.Count <= controlIndex || control[controlIndex] == null
? 0 : control[controlIndex].Width
+ control[controlIndex].Margin.Horizontal)
+ horizontalMargin;
layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, columnWidth));
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
return layoutPanel;
}
示例12: Main
static void Main()
{
var numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
var odd = numbers.WhereNot(x => x % 2 == 0);
Console.WriteLine(string.Join(" ", odd));
var numbersBiggerThanTen = numbers.WhereNot(LessThanTen);
Console.WriteLine(string.Join(" ", numbersBiggerThanTen));
Console.WriteLine();
var students = new List<Student>()
{
new Student("Stavri",5.5),
new Student("Loshiq",2),
new Student("Me4a", 3.50),
new Student("Anatoli", 4.4),
new Student("Rambo", 5.95)
};
Console.WriteLine(students.Max(student => student.Grade));
Console.WriteLine(students.Min(Grade));
Console.WriteLine();
Console.WriteLine(students.Max(Name));
Console.WriteLine(students.Min(student => student.Name));
}
示例13: ParseMap
private static Map ParseMap(string zone, string[] lines) {
Map tmpMap = new Map();
tmpMap.zone = zone;
if (tmpMap.zone != "") {
List<MapLineSegment> segmentList = new List<MapLineSegment>();
foreach (string l in lines) {
if (l[0] == 'L') {
segmentList.Add(ParseSegment(l));
}
else if (l[0] == 'P') {
//parse place
}
}
//group up line segments according to color(RGB) value, then create one pen for each color used
//this should greatly lower the overhead for creating brush and pen objects
//*edit* aparently not.
List<MapLineSegment> distinctSegments = segmentList.Distinct(new MapLineSegmentColorComparer()).ToList();
foreach (MapLineSegment colorSource in distinctSegments) {
List<MapLineSegment> tmpSegmentList = segmentList.FindAll(x => x.color == colorSource.color);
SolidColorBrush colorBrush = new SolidColorBrush(colorSource.color);
Pen tmpPen = new Pen(colorBrush, 1.0);
tmpMap.lineList.Add(new MapLine(tmpSegmentList, tmpPen));
}
if (segmentList.Count > 0) {
tmpMap.maxX = Math.Max(segmentList.Max(x => x.aX), segmentList.Max(x => x.bX));
tmpMap.maxY = Math.Max(segmentList.Max(x => x.aY), segmentList.Max(x => x.bY));
tmpMap.minX = Math.Min(segmentList.Min(x => x.aX), segmentList.Min(x => x.bX));
tmpMap.minY = Math.Min(segmentList.Min(x => x.aY), segmentList.Min(x => x.bY));
tmpMap.width = tmpMap.maxX - tmpMap.minX;
tmpMap.height = tmpMap.maxY - tmpMap.minY;
tmpMap.depth = tmpMap.maxZ - tmpMap.minZ;
}
}
return tmpMap;
}
示例14: AddPlotSeries
private void AddPlotSeries(List<Tuple<double, double>> ansv, double stepX, double stepY)
{
_stepX = stepX;
_stepY = stepY;
if (!_firstLoaded)
DrawGrid(ansv.Min(item => item.Item1), ansv.Max(item => item.Item1), stepX,
ansv.Min(item => item.Item2), ansv.Max(item => item.Item2), stepY);
MyCanvas.Children.Add(GenerateSeriesPath(ansv));
}
示例15: Main
static void Main()
{
string numbersString = Console.ReadLine();
if (numbersString == "")
{
Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
}
else
{
decimal[] numbers = Array.ConvertAll(numbersString.Split(' '), decimal.Parse);
List<decimal> odd = new List<decimal>();
List<decimal> even = new List<decimal>();
for (int i = 0; i < numbers.Length; i++)
{
if (i % 2 == 0)
{
odd.Add(numbers[i]);
}
else
{
even.Add(numbers[i]);
}
}
if ((odd.Count == 0 && even.Count == 0) || numbersString == "")
{
Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
}
if (even.Count == 0)
{
decimal oddSum = odd.Sum();
decimal oddMin = odd.Min();
decimal oddMax = odd.Max();
Console.WriteLine("OddSum={0:0.##}, OddMin={1:0.##}, OddMax={2:0.##}, EvenSum=No, EvenMin=No, EvenMax=No", oddSum, oddMin, oddMax);
}
else
{
decimal oddSum = odd.Sum();
decimal oddMin = odd.Min();
decimal oddMax = odd.Max();
decimal evenSum = even.Sum();
decimal evenMin = even.Min();
decimal evenMax = even.Max();
Console.WriteLine("OddSum={0:0.##}, OddMin={1:0.##}, OddMax={2:0.##}, EvenSum={3:0.##}, EvenMin={4:0.##}, EvenMax={5:0.##}"
, oddSum, oddMin, oddMax, evenSum, evenMin, evenMax);
}
}
}