本文整理汇总了C#中IList.Last方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Last方法的具体用法?C# IList.Last怎么用?C# IList.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.Last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GuerillaPreProcessMethod
protected static void GuerillaPreProcessMethod(BinaryReader binaryReader, IList<tag_field> fields)
{
var field = fields.Last(x => x.type != field_type._field_terminator);
fields.Remove(field);
field = fields.Last(x => x.type != field_type._field_terminator);
fields.Remove(field);
}
示例2: BuildLastSeason
private IList<TripleExponentialEntry> BuildLastSeason(IList<TripleExponentialEntry> currSeason,
IEnumerable<DataEntry> dataEntries, int currPeriod)
{
//building the last season is similar to NextSeason, but uses the same Ft and Tt once calculated for the first entry.
var currentFt = currSeason.Last().Ft;
var currentTt = currSeason.Last().Tt;
double currentSt = currSeason.Last().St, lastSt = currSeason.Last().St;
var lastActual = dataEntries.Last().Value;
IList<TripleExponentialEntry> newSeason = new List<TripleExponentialEntry>();
currentFt = (_alpha*(lastActual/lastSt)) + ((1 - _alpha)*(currentTt + currentFt));
currentTt = (_beta*(currentFt - currSeason.Last().Ft)) + ((1 - _beta)*currentTt);
for (var currSeasonIndex = 1; currSeasonIndex <= _periodsPerSeason; currSeasonIndex++)
{
var lastPeriodActual =
dataEntries.ElementAt((currPeriod + currSeasonIndex) - _periodsPerSeason - 2).Value;
var lastPeriodFt = currSeason.ElementAt(currSeasonIndex - 1).Ft;
var lastPeriodSt = currSeason.ElementAt(currSeasonIndex - 1).St;
currentSt = (_gamma*(lastPeriodActual/lastPeriodFt)) + ((1 - _gamma)*lastPeriodSt);
newSeason.Add(new TripleExponentialEntry
{
Ft = currentFt,
Tt = currentTt,
St = currentSt,
Forecast = (currentFt + (currentTt*currSeasonIndex))*currentSt
});
}
return newSeason;
}
示例3: Invoke
public void Invoke(char[] code)
{
Tokens = new List<CToken>();
var currentToken = new StringBuilder();
// todo remove whitespace and comments
foreach (char c in code)
{
if (char.IsWhiteSpace(c))
{
continue;
}
switch (c)
{
case Punctuations.OPEN_PARENS:
Tokens.Add(new CToken(currentToken.ToString(), NodeType.Caller));
Tokens.Add(new CToken(Punctuations.OPEN_PARENS.ToString(), NodeType.Punctuation));
currentToken = new StringBuilder();
break;
case Punctuations.CLOSE_PARENS:
Tokens.Add(new CToken(currentToken.ToString(), NodeType.Variable));
Tokens.Add(new CToken(Punctuations.CLOSE_PARENS.ToString(), NodeType.Punctuation));
currentToken = new StringBuilder();
break;
case Punctuations.COMMA:
if (currentToken.Length != 0)
{
Tokens.Add(new CToken(currentToken.ToString(), NodeType.Variable));
}
Tokens.Add(new CToken(Punctuations.COMMA.ToString(), NodeType.Punctuation));
currentToken = new StringBuilder();
break;
case Punctuations.DOUBLE_QUOTE:
if (currentToken.Length == 0)
{
Tokens.Add(new CToken(Punctuations.DOUBLE_QUOTE.ToString(), NodeType.Punctuation));
}
else
{
Tokens.Add(new CToken(currentToken.ToString(), NodeType.String));
Tokens.Add(new CToken(Punctuations.DOUBLE_QUOTE.ToString(), NodeType.Punctuation));
currentToken = new StringBuilder();
}
break;
case Punctuations.SEMI_COL:
{
Tokens.Add(new CToken(Punctuations.SEMI_COL.ToString(), NodeType.Punctuation));
break;
}
}
if (char.IsLetterOrDigit(c) || (Tokens.Last() != null && Tokens.Last().Value == "\"" && c != '"'))
{
currentToken.Append(c);
}
}
}
示例4: PropertyAccessor
public PropertyAccessor(IList<PropertyInfo> propertyChain, Type genericType, Type collectionType) : this(propertyChain)
{
if (genericType == null) throw new ArgumentNullException("genericType");
GenericType = genericType;
CollectionType = collectionType;
AddMethod = CollectionType.GetMethod("Add");
ItemPropertyInfo = propertyChain.Last().PropertyType.GetProperty("Item");
RemoveAtMethod = propertyChain.Last().PropertyType.GetMethod("RemoveAt");
IsCollection = true;
}
示例5: AddWays
public static void AddWays(this Polygon<OSMNode> polygon, IList<OSMWay> ways, OSMDB db)
{
if (ways.Count == 1) {
// Check if the created polygon is closed
if (ways[0].Nodes.Count > 0 && ways[0].Nodes.First() != ways[0].Nodes.Last()) {
throw new ArgumentException("Ways does not form a closed polygon");
}
for (int i = 0; i < ways[0].Nodes.Count - 1; i++) {
polygon.AddVertex(db.Nodes[ways[0].Nodes[i]]);
}
}
else {
int lastVertexID = 0;
if (ways[0].Nodes.First() == ways.Last().Nodes.First() || ways[0].Nodes.Last() == ways.Last().Nodes.First()) {
lastVertexID = ways.Last().Nodes.First();
}
else {
lastVertexID = ways.Last().Nodes.Last();
}
//// Check orientation of the first way
//if (ways[0].Nodes.First() == ways[1].Nodes.First() || ways[0].Nodes.First() == ways[1].Nodes.First()) {
// for (int ii = ways[0].; ii < verticesToAdd.Count - 1; ii++) {
// AddVertex(verticesToAdd[ii]);
// }
//}
for (int i = 0; i < ways.Count; i++) {
List<int> verticesToAdd = new List<int>();
// Checks the way orienatation and picks nodes in correct order
if (lastVertexID == ways[i].Nodes[0]) {
verticesToAdd.AddRange(ways[i].Nodes);
}
else if (lastVertexID == ways[i].Nodes.Last()) {
verticesToAdd.AddRange(ways[i].Nodes.Reverse());
}
else {
throw new ArgumentException("Can not create polygon, ways aren't connected");
}
for (int ii = 0; ii < verticesToAdd.Count - 1; ii++) {
polygon.AddVertex(db.Nodes[verticesToAdd[ii]]);
}
lastVertexID = verticesToAdd.Last();
}
// Check if the created polygon is closed
if (polygon.VerticesCount > 0 && polygon.Vertices.First() != db.Nodes[lastVertexID]) {
throw new ArgumentException("Ways does not form a closed polygon");
}
}
}
示例6: Filter
static IEnumerable<BottomProfilePoint> Filter(IList<BottomProfilePoint> source)
{
var curProfilePoint = source[0];
yield return curProfilePoint;
foreach (var point in source.Where(point => curProfilePoint.Depth != point.Depth))
{
curProfilePoint = point;
yield return point;
}
if (curProfilePoint.Range < source.Last().Range) yield return source.Last();
}
示例7: AssignFragmentPeak
public void AssignFragmentPeak(IList<IAtomContainer> fragments, IEnumerable<Peak> peakList, double mzabs, double mzppm)
{
hits = new List<PeakMolPair>();
hitsAll = new List<PeakMolPair>();
foreach (var peak in peakList)
{
var haveFoundAMatch = false;
foreach (var fragment in fragments)
{
//matched peak
int hydrogensAdded;
double matchedMass;
double hydrogenPenalty;
if (MatchByMass(fragment, peak.Mass, mzabs, mzppm, out matchedMass, out hydrogenPenalty, out hydrogensAdded))
{
var match = new PeakMolPair(fragment, peak, matchedMass, GetMolecularFormulaAsString(fragment), hydrogenPenalty, double.Parse((string)fragment.getProperty("BondEnergy"), CultureInfo.InvariantCulture), GetNeutralChange(fragment, hydrogensAdded));
hitsAll.Add(match);
// If we don't yet have a match, add it
if (!haveFoundAMatch)
{
hits.Add(match);
haveFoundAMatch = true;
}
// If we do have a match, replace it if this new match has a lower hydrogen penalty
else if (hydrogenPenalty < hits.Last().HydrogenPenalty)
{
hits.RemoveAt(hits.Count - 1);
hits.Add(match);
}
}
}
}
}
示例8: FromImportCompletionAnalysis
public FromImportCompletionAnalysis(IList<ClassificationSpan> tokens, ITrackingSpan span, ITextBuffer textBuffer, CompletionOptions options)
: base(span, textBuffer, options)
{
Debug.Assert(tokens[0].Span.GetText() == "from");
int beforeImportToken = tokens
.TakeWhile(tok => !(tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Keyword) && tok.Span.GetText() == "import"))
.Count();
bool lastIsDot = tokens.Last().ClassificationType.IsOfType(JPredefinedClassificationTypeNames.Dot);
_modulesOnly = beforeImportToken == tokens.Count;
_noCompletions = !_modulesOnly && lastIsDot;
_includeStar = beforeImportToken == tokens.Count - 1;
if (beforeImportToken >= 2) {
// If there are at least two tokens ('from' <name>) before the
// 'import' token, use completions from that package.
if (beforeImportToken < tokens.Count || lastIsDot) {
_namespace = tokens
.Take(beforeImportToken)
.Where(tok => tok.ClassificationType.IsOfType(PredefinedClassificationTypeNames.Identifier))
.Select(tok => tok.Span.GetText())
.ToArray();
} else {
_importKeywordOnly = true;
}
}
}
示例9: SortCollectedList
void SortCollectedList()
{
var sorted = _collectedList.OrderByDescending(x => x.Value);
_collectedList = null;
_collectedList = sorted.Cast<MapData>().ToList();
_lowest = _collectedList.Last().Value;
}
示例10: PropertyExpression
protected PropertyExpression(object obj, IEnumerable<PropertyExpressionPart> parts)
{
if (obj == null)
throw new ArgumentNullException("obj");
if (parts == null)
throw new ArgumentNullException("parts");
/*foreach (object item in parts)
{
if (item == null)
{
throw new ArgumentException("An item inside the enumeration was null.", "parts");
}
}*/
if (parts.Cast<object>().Any(item => item == null))
{
throw new ArgumentException(Resources.AnItemWasNull, "parts");
}
_parts = new List<PropertyExpressionPart>(parts);
if (_parts.Count == 0)
throw new ArgumentException(Resources.OnePartRequired, "parts");
_finalPart = _parts.Last();
//whenever the final part's value changes, that means the value of the expression as a whole has changed
_finalPart.ValueChanged += delegate
{
OnValueChanged();
};
//assign the initial object in the potential chain of objects resolved by the expression parts
_parts[0].Object = obj;
}
示例11: ParseRealization
private void ParseRealization(IList<Double> realization)
{
Double repeatedValue = realization.Last(); // last value it's the same as cycle start value
Int32 cycleStartIndex = realization.IndexOf(repeatedValue);
Appendix = realization.Take(cycleStartIndex).ToList();
Cycle = realization.Skip(cycleStartIndex).Take(realization.Count - cycleStartIndex - 1).ToList();
}
示例12: CheckFirstAndLastPoint
private void CheckFirstAndLastPoint(IList<Point> points)
{
if (this.DistanceIsTooSmall(points.Last(), points.First()))
{
points.RemoveAt(points.Count - 1);
}
}
示例13: CheckFirstAndLastPoint
private void CheckFirstAndLastPoint(IList<DepthPointEx> points)
{
if (PointsAreClose(points.Last(), points.First()))
{
points.RemoveAt(points.Count - 1);
}
}
示例14: MainWindow
public MainWindow()
{
InitializeComponent();
Loaded += (sender, e) => ClearValue(SizeToContentProperty);
_allControllerViewModels =
(from type in GetType().Assembly.GetTypes()
where !type.IsInterface && typeof(IController).IsAssignableFrom(type)
let viewModel = new ControllerViewModel((IController)Activator.CreateInstance(type))
orderby viewModel.SortIndex, viewModel.Library, viewModel.Description
select viewModel).ToList();
_allControllerViewModels.First().IsChecked = true;
ControllerGroups.ItemsSource = _allControllerViewModels.GroupBy(viewModel => viewModel.Library);
_allResolutionViewModels = new[] {
new ResolutionViewModel(800, 600, 50, 42),
new ResolutionViewModel(1024, 768, 64, 54),
new ResolutionViewModel(1280, 1024, 80, 73),
new ResolutionViewModel(1440, 900, 90, 64),
};
_allResolutionViewModels.Last(
res => res.Width <= SystemParameters.PrimaryScreenWidth &&
res.Height <= SystemParameters.PrimaryScreenHeight).IsChecked = true;
Resolutions.ItemsSource = _allResolutionViewModels;
RunResults.ItemsSource = _runResults;
}
示例15: SolveFive
private int SolveFive(BombSettings settings, IList<Color> colors)
{
if (settings.SerialLastDigit == Parity.NotSet)
{
throw new NeedSerialLastDigitException();
}
// If the last wire is black and the last digit of the serial number is odd, cut the fourth wire.
else if (colors.Last() == Color.Black && settings.SerialLastDigit == Parity.Odd)
{
return 4;
}
// Otherwise, if there is exactly one red wire and there is more than one yellow wire, cut the first wire.
else if (colors.Count(c => c == Color.Red) == 1 && colors.Count(c => c == Color.Yellow) > 1)
{
return 1;
}
// Otherwise, if there are no black wires, cut the second wire.
else if (colors.Count(c => c == Color.Black) == 0)
{
return 2;
}
// Otherwise, cut the first wire.
else
{
return 1;
}
}