本文整理汇总了C#中List.Min方法的典型用法代码示例。如果您正苦于以下问题:C# List.Min方法的具体用法?C# List.Min怎么用?C# List.Min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Min方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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);
}
示例3: getSmartPosition
public static Tuple<int, int> getSmartPosition(List<System.Drawing.Rectangle> listRect, System.Drawing.Rectangle rect)
{
HashSet<Rectangle> hsRect = new HashSet<Rectangle>(listRect);
List<Rectangle> listGotCollide = new List<Rectangle>();
foreach (var item in hsRect)
{
Rectangle intersect = Rectangle.Intersect(item, rect);
if (intersect.Width > 1 && intersect.Height > 1)
{
listGotCollide.Add(item);
}
}
int xOuter = listGotCollide.Min(item => item.X);
int yOuter = listGotCollide.Min(item => item.Y);
int xInner = xOuter + 32;
int yInner = yOuter + 32;
int xResult = Math.Abs(rect.X - xOuter) > Math.Abs(rect.X - xInner) ? xInner : xOuter;
int yResult = Math.Abs(rect.Y - yOuter) > Math.Abs(rect.Y - yInner) ? yInner : yOuter;
Tuple<int, int> result = new Tuple<int, int>(xResult, yResult);
return result;
}
示例4: ShipOnMap
public ShipOnMap(Texture2D texture, Texture2D circle, Vector2 position, Vector2 scale, List<Ship> ships)
{
Texture = texture;
Circle = circle;
Scale = scale;
this.position = position;
this.velocity = ships.Min(x => x.Velocity);
FinalWidth = position.X + texture.Width * scale.X;
FinalHeight = position.Y + texture.Height * scale.Y;
Ships = ships;
IsPressed = false;
IsOwnByThisPlayer = false;
IsRightButtonPressed = false;
IsMoving = false;
SpeedMod = ships.Min(x => x.SpeedMod);
Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
CircleOrigin = new Vector2((Circle.Width - Texture.Width) / 2, (Circle.Height - Texture.Height) / 2);
CircleScale = Scale;
Rotation = 0;
Timer = 0;
Mobility = 0;
Target = null;
IsMovingToSystem = false;
IsVisible = true;
}
示例5: 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));
}
示例6: 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;
}
示例7: 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));
}
示例8: Plot
/// <summary>
///
/// </summary>
/// <param name="table"></param>
/// <param name="chart"></param>
/// <param name="indexAxisX"></param>
/// <param name="indexAxisY"></param>
public void Plot(DataTable table, Chart chart, int indexAxisX, int indexAxisY)
{
if (HasNull(table))
{
MessageBox.Show(@"Iterate data first!");
}
else
{
try
{
var xValue = new List<double>();
var yValue = new List<double>();
foreach (var series in chart.Series)
{
series.Points.Clear();
}
for (var i = 1; i < table.Columns.Count; i++)
{
xValue.Add(
Convert.ToDouble(table.Rows[indexAxisX][i].ToString()));
yValue.Add(
Convert.ToDouble(table.Rows[indexAxisY][i].ToString()));
}
if (Math.Abs(xValue.Min() - xValue.Max()) < 0.0000001 ||
Math.Abs(yValue.Min() - yValue.Max()) < 0.0000001)
{
MessageBox.Show(@"The selected data cannot be charted!");
}
else
{
chart.Series[0].Points.DataBindXY(xValue, yValue);
chart.Series[0].ChartType = SeriesChartType.FastLine;
chart.Series[0].Color = Color.Black;
chart.ChartAreas[0].AxisX.Maximum = xValue.Max();
chart.ChartAreas[0].AxisX.Minimum = xValue.Min();
chart.ChartAreas[0].AxisY.Maximum = yValue.Max();
chart.ChartAreas[0].AxisY.Minimum = yValue.Min();
chart.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
chart.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
chart.ChartAreas[0].AxisX.Title =
table.Rows[indexAxisX][0].ToString();
chart.ChartAreas[0].AxisY.Title =
table.Rows[indexAxisY][0].ToString();
chart.Series[0].IsVisibleInLegend = false;
}
}
catch (Exception ex)
{
MessageBox.Show(@"Chart error: " + ex.Message);
}
}
}
示例9: 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);
}
}
}
示例10: MinPoint
public static Point MinPoint( List<Point> points, Axis axis)
{
double min;
if (axis == Axis.X)
{
min = points.Min(p => p.X);
return points.FirstOrDefault(p => DoubleCompare(p.X , min));
}
min = points.Min(p => p.Y);
return points.FirstOrDefault(p => DoubleCompare(p.Y, min));
}
示例11: VectorPath
public VectorPath(List<VectorPathSegment> seg)
{
segments = seg;
Length = segments.Sum(p => p.Length);
float top = segments.Min(p => p.Boundings.Top);
float bot = segments.Max(p => p.Boundings.Bottom);
float lef = segments.Min(p => p.Boundings.Left);
float rig = segments.Max(p => p.Boundings.Right);
Boundings = new FRectangle(lef, top, rig-lef, bot-top);
}
示例12: boundingRectangle
public Rectangle boundingRectangle(List<Point> points)
{
// Add checks here, if necessary, to make sure that points is not null,
// and that it contains at least one (or perhaps two?) elements
var minX = points.Min(p => p.X);
var minY = points.Min(p => p.Y);
var maxX = points.Max(p => p.X);
var maxY = points.Max(p => p.Y);
return new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY));
}
示例13: GetEnvelope
public static void GetEnvelope(double lat, double lon, double dist, out double minLat, out double minLon, out double maxLat, out double maxLon)
{
var gc = new GeodeticCalculator();
var endpoints = new List<GlobalCoordinates>();
endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(0), dist * 1000.0));
endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(90), dist * 1000.0));
endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(180), dist * 1000.0));
endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(270), dist * 1000.0));
minLat = endpoints.Min(x => x.Latitude.Degrees);
maxLat = endpoints.Max(x => x.Latitude.Degrees);
minLon = endpoints.Min(x => x.Longitude.Degrees);
maxLon = endpoints.Max(x => x.Longitude.Degrees);
}
示例14: Sorting
public static void Sorting(List<int> array)
{
int[] sortedArray = new int[array.Count];
for (int i = 0; i < sortedArray.Length; i++)
{
sortedArray[i] = array.Min();
array.Remove(array.Min());
}
Console.WriteLine("The sorted array is: ");
for (int i = 0; i < sortedArray.Length; i++)
{
Console.WriteLine(sortedArray[i]);
}
}
示例15: AssignLabel
private void AssignLabel()
{
Doggies.ForEach(x =>
{
var distances = new List<double> () { GetEuclideanDistance(x, chihuahuaCentroid),
GetEuclideanDistance(x, beaglesCentroid),
GetEuclideanDistance(x, daschundCentroid) };
if (distances[0] == distances.Min()) x.Label = Label.Chihuahuas;
else if (distances[1] == distances.Min()) x.Label = Label.Beagles;
else x.Label = Label.Daschunds;
FixCentroids(x.Label);
});
}