本文整理汇总了C#中IList.Min方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Min方法的具体用法?C# IList.Min怎么用?C# IList.Min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.Min方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetMinMax
public void SetMinMax(IList<Point> points)
{
if (_isMaxMinSet)
{
var minX = points.Min(point => point.X);
MinX = minX < MinX ? minX : MinX;
var maxX = points.Max(point => point.X);
MaxX = maxX > MaxX ? maxX : MaxX;
var minY = points.Min(point => point.Y);
MinY = minY < MinY ? minY : MinY;
var maxY = points.Max(point => point.Y);
MaxY = maxY > MaxY ? maxY : MaxY;
}
else
{
MinX = points.Min(point => point.X);
MaxX = points.Max(point => point.X);
MinY = points.Min(point => point.Y);
MaxY = points.Max(point => point.Y);
_isMaxMinSet = true;
}
SetOriginPoint(GetDelta());
}
示例2: Sort
/// <summary>
/// I feel like this way is a little bit more optimized since it saves space
/// there is still the possibility of empty space beetwen min,max
/// but atleast it gets rid of the space from 0 to min
///
/// This will also work with negative numbers.
/// </summary>
public static int[] Sort(IList<int> data, int min, int max)
{
Contract.Ensures(data != null, "data cannot be a null pointer");
Contract.Ensures(min == data.Min(), "wrong min submitted");
Contract.Ensures(max == data.Max(), "wrong max submitted");
int[] count = new int[(max - min) + 1];
int[] sorted = new int[data.Count];
// Add the elements in reverse order big --> small
// NOTE: Could do key - min instead for order small --> big
foreach (int key in data)
{
count[max - key] += 1;
}
// Transfer the temp array to the sorted array from small --> big
int sortedIndex = data.Count - 1;
for (int i = 0; i < count.Length; i++)
{
// How often did we have this number in the input?
int number = max - i;
for (int j = 0; j < count[i]; j++)
{
sorted[sortedIndex--] = number;
}
}
return sorted;
}
示例3: ResolveNormal
private static int ResolveNormal(IList<int> pancakes)
{
int maxvalue = pancakes.Max();
int minvalue = pancakes.Min();
if (minvalue == maxvalue)
return maxvalue;
int secondmaxvalue = pancakes.Where(n => n != maxvalue).Max();
IList<int> newpancakes = new List<int>();
int steps = maxvalue - secondmaxvalue;
foreach (int value in pancakes)
{
if (value == maxvalue)
newpancakes.Add(secondmaxvalue);
else if (value > steps)
newpancakes.Add(value - steps);
}
if (newpancakes.Count == 0)
return 1;
return Resolve(newpancakes) + steps;
}
示例4: Render
/// <summary>
/// Convert numbers to spark chart strings.
/// </summary>
/// <param name="data">List or Array of numbers</param>
/// <returns>empty string if <paramref name="data"/>is <code>null</code> or empty.</returns>
public static String Render(IList<double> data)
{
var ticks = TickProvider.Ticks;
if (data == null || data.Count == 0)
return string.Empty;
char[] res = new char[data.Count()];
double min = data.Min();
double max = data.Max();
double step = (max - min) / (ticks.Length - 1);
if (step.Equals(0d)) step = 1;
for (var i = 0; i < data.Count(); i++)
{
var val = data[i];
double d = (val - min)/step;
// if it's 10^-10 close to its rounded, round; floor otherwise
int tick = (int) ((Math.Abs(Math.Round(d) - d) < 1e-10) ? Math.Round(d) : Math.Floor((val - min) / step));
res[i] = ticks[tick];
}
return new string(res);
}
示例5: GetIntervalsForNumberOfClasses
/// <summary>
/// Generates intervals based on type, numberOfClasses and values.
/// </summary>
/// <param name="values"></param>
/// <param name="type"></param>
/// <param name="numberOfClasses"></param>
/// <returns></returns>
public static IList<Interval> GetIntervalsForNumberOfClasses(IList<Single> values, QuantityThemeIntervalType type, int numberOfClasses)
{
int index = 0;
var intervals = new List<Interval>();
var lowValue = values.Min();
var highValue = values.Max();
if (type == QuantityThemeIntervalType.NaturalBreaks)
{
ArrayList.Adapter((IList)values).Sort(); // performance, works 20% faster than layerAttribute.AttributeValues.Sort();
}
for (int i = 0; i < numberOfClasses; i++)
{
float intervalMin;
float intervalMax;
if (type == QuantityThemeIntervalType.EqualIntervals)
{
intervalMin = lowValue + i * ((highValue - lowValue) / numberOfClasses);
intervalMax = lowValue + (i + 1) * ((highValue - lowValue) / numberOfClasses);
}
else
{
intervalMin = Convert.ToSingle(values[index]);
index = (int)Math.Ceiling((double)(i + 1) / numberOfClasses * (values.Count - 1));
intervalMax = Convert.ToSingle(values[index]);
}
var interval = new Interval(intervalMin, intervalMax);
intervals.Add(interval);
}
return intervals;
}
示例6: DisplayStats
static void DisplayStats(IList<Response> responses)
{
if (!responses.Any())
{
return;
}
var average = responses.Average(x => (x.EndUtc - x.StartUtc).TotalMilliseconds);
ClearLine();
Console.WriteLine("Average time: {0} ms", Convert.ToInt32(average));
var min = responses.Min(x => x.StartUtc);
var max = responses.Max(x => x.EndUtc);
var count = responses.Count;
var timespan = Convert.ToInt32((max - min).TotalMilliseconds);
timespan = timespan == 0 ? 0 : timespan / 1000;
var rps = timespan == 0 ? 0 : count / timespan;
ClearLine();
Console.WriteLine("Performance: {0} rps ({1} reqs in {2})", Convert.ToInt32(rps), responses.Count, timespan);
ClearLine();
Console.WriteLine("Threads: {0}", responses.Select(x => x.TaskId).Distinct().Count());
ClearLine();
Console.WriteLine("Errors: {0}", responses.Count(x => !x.Success));
}
示例7: ConvexHull
public List<Point> ConvexHull(IList<Point> points)
{
if (points.Count < 3)
{
throw new ArgumentException("At least 3 points reqired", "points");
}
List<Point> hull = new List<Point>();
// get leftmost point
Point vPointOnHull = points.Where(p => p.X == points.Min(min => min.X)).First();
Point vEndpoint;
do
{
hull.Add(vPointOnHull);
vEndpoint = points[0];
for (int i = 1; i < points.Count; i++)
{
if ((vPointOnHull.IsTheSame(vEndpoint)) || (Orientation(vPointOnHull, vEndpoint, points[i]) == -1))
{
vEndpoint = points[i];
}
}
vPointOnHull = vEndpoint;
}
while (!vEndpoint.IsTheSame(hull[0]));
return hull;
}
示例8: CalculateDeceitfulWar
public int CalculateDeceitfulWar(IList<double> first, IList<double> second)
{
if (first.Count == 0)
return 0;
double min1 = first.Min();
double min2 = second.Min();
bool win = false;
double play1;
double play2;
if (min1 < min2)
{
play1 = min1;
play2 = second.Max();
}
else
{
play1 = min1;
play2 = min2;
win = true;
}
var newfirst = first.Where(n => n != play1).ToList();
var newsecond = second.Where(n => n != play2).ToList();
return CalculateDeceitfulWar(newfirst, newsecond) + (win ? 1 : 0);
}
示例9: AddWeekToSeason
public SeasonWeek AddWeekToSeason(int seasonId, IList<RealWorldFixture> fixtures)
{
var season = LoadSeason(seasonId);
var currentFinalWeek = season.Weeks.Any() ? season.Weeks.Max(w => w.WeekNumber) : 0;
if (currentFinalWeek == season.NumberOfWeeks)
throw new InvalidOperationException("Season has full complement of weeks already");
var predsCutoffDate = fixtures.Min(f => f.KickOff).AddHours(-1);
var addedWeek = new SeasonWeek
{
WeekNumber = currentFinalWeek + 1,
RealWorldFixtures = fixtures,
PredsCutOffDate = predsCutoffDate,
Season = season,
};
foreach (var fixture in fixtures)
{
fixture.SeasonWeek = addedWeek;
}
season.Weeks.Add(addedWeek);
_seasonRepository.Save(season);
return addedWeek;
}
示例10: Draw
public override void Draw(
IList<Point> points,
double thickness,
int miterLimit,
ILogicalToScreenMapper logicalToScreenMapper)
{
var pointsCount = points.Count;
var firstPoint = points[0];
var lastPoint = points[pointsCount - 1];
var highestValue = _useHighest ? points.Max(it => it.Y) : 0;
var lowestValue = _useLowest ? points.Min(it => it.Y) : 0;
double baselineValue;
// Auf gleiche Höhe bringen
if (_useBaseline)
baselineValue = logicalToScreenMapper.MapY(_baselineValue);
else if (_useHighest)
baselineValue = highestValue;
else if (_useLowest)
baselineValue = lowestValue;
else
{
baselineValue = firstPoint.Y > lastPoint.Y
? lastPoint.Y
: firstPoint.Y;
}
using (var dc = RenderOpen())
{
for (var i = 1; i < points.Count; i++)
{
var previousPoint = points[i - 1];
var currentPoint = points[i];
var previousY = previousPoint.Y;
// -1 weil: 1 Pixel nach links verschieben bewirkt, dass die Löcher zwischen den Rechtecken nicht mehr auftauchen
// nicht mehr nach 1 verschieben, weil der Fall bei Kriko (kleine Löcher in den Kurven) sowieso nicht vorkommt
// var previousX = previousPoint.X - 1;
var previousX = previousPoint.X;
// Rect kann mit negativen Höhen nicht umgehen, deshalb die komischen Expressions
var height = previousY > baselineValue ? previousY - baselineValue : baselineValue - previousY;
var y = previousY > baselineValue ? baselineValue : previousY;
var rectangle = new Rect(
previousX,
height == 0 ? y - 1 : y, // Linie um 1 nach oben verschieben, damit die Linien nicht optisch nach unten versetzt sind
currentPoint.X - previousX,
height == 0d ? 1 : height);
dc.DrawRectangle(
Brushes.White,
new Pen(
Brushes.White,
0)
// brauchen wir nicht mehr (siehe oben - height == 0): thickness == 1 ? 0.25 : thickness)
{
MiterLimit = miterLimit
},
rectangle);
}
}
}
示例11: Do
public AggregationOperationResult Do(IList<double> input)
{
if (input == null)
throw new ArgumentNullException("input");
if (!input.Any())
throw new InvalidOperationException("No elements to aggregate");
return new AggregationOperationResult(AggregationType.Min,input.Min());
}
示例12: FindDepartmentWithMinSortOrder
private static Department FindDepartmentWithMinSortOrder(IList<Department> departments)
{
int firstSortOrder = departments.Min(d => d.SortOrder);
return (from d in departments
where d.SortOrder == firstSortOrder
select d).First();
}
示例13: Do
public AggregationOperationResult Do(IList<UniversalValue> input)
{
if (input == null)
throw new ArgumentNullException("input");
AggregationOperationResult result = new AggregationOperationResult();
result.Add("min", input.Min());
return result;
}
示例14: GetTheta
private int GetTheta(int current, IList<int> sortedCardinalities)
{
var result = sortedCardinalities.Count(i => i >= current);
if (current != sortedCardinalities.Min())
{
result = result + 1;
}
return result;
}
示例15: GetFontSizes
public IList<WordIntPair> GetFontSizes(IList<WordIntPair> wordsAndFreqs, InputOptions options)
{
int minCount = wordsAndFreqs.Min(t => t.Number);
int maxCount = wordsAndFreqs.Max(t => t.Number);
return wordsAndFreqs.Select(tuple => new WordIntPair(
tuple.Word,
CountFont(tuple.Number, options.MaxFont, options.MinFont, minCount, maxCount)))
.ToList();
}