本文整理汇总了C#中List.Last方法的典型用法代码示例。如果您正苦于以下问题:C# List.Last方法的具体用法?C# List.Last怎么用?C# List.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateList
/// <summary>
/// Convert List of Trades to List of Completed Trades
/// </summary>
/// <param name="TradesOnly"></param>
/// <returns></returns>
public static List<CompletedTrade> CreateList(List<Trade> TradesOnly)
{
var CompList = new List<CompletedTrade>();
var even = TradesOnly.Count % 2;
int back = even == 2 ? 0 : 1;
for (int x = 0; x < TradesOnly.Count - back; x += 2)
{
CompletedTrade t = new CompletedTrade();
t.OpenTrade = TradesOnly[x];
t.CloseTrade = TradesOnly[x + 1];
CompList.Add(t);
}
if (TradesOnly.Last() != CompList.Last().CloseTrade)
{
CompletedTrade last = new CompletedTrade();
last.OpenTrade = TradesOnly.Last();
last.CloseTrade.TimeStamp = last.OpenTrade.TimeStamp;
last.CloseTrade.BuyorSell = Trade.BuySell.None;
last.CloseTrade.Reason = Trade.Trigger.None;
last.CloseTrade.CurrentDirection = last.OpenTrade.CurrentDirection;
last.CloseTrade.TradedPrice = last.OpenTrade.TradedPrice;
CompList.Add(last);
}
return CompList;
}
示例2: FindConvexPolygon
public static PointCollection FindConvexPolygon(List<Point> points)
{
List<Point> top = new List<Point>();
List<Point> bottom = new List<Point>();
IEnumerable<Point> finalTop;
IEnumerable<Point> finalBottom;
points.Sort((x, y) => { return (int) (x.X - y.X); });
double deltaX = points.Last().X - points.First().X;
double deltaY = points.Last().Y - points.First().Y;
double denominator = (Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2));
for (int i = 1; i < points.Count - 1; i++)
if (MinimumDistanceBetweenPointAndLine2D(points.First(), points.Last(), points[i], deltaX, deltaY,
denominator))
bottom.Add(points[i]);
else
top.Add(points[i]);
top.Insert(0, points.First());
top.Add(points.Last());
bottom.Insert(0, points.First());
bottom.Add(points.Last());
finalTop = ConvexHullCore(top, true);
finalBottom = ConvexHullCore(bottom, false);
return new PointCollection(finalTop.Union(finalBottom.Reverse()));
}
示例3: LiedVerzen
/// <summary>
/// Maak een mooie samenvatting van de opgegeven nummers
/// </summary>
/// Probeer de nummers samen te vatten door een bereik te tonen.
/// Waar niet mogelijk toon daar gewoon komma gescheiden nummers.
/// Als het in beeld is dan wordt de eerste in ieder geval los getoond.
/// <remarks>
/// </remarks>
private static string LiedVerzen(ILiturgieDisplay regelDisplay, bool toonEersteLos, IEnumerable<ILiturgieContent> vanDelen = null)
{
if (regelDisplay.VersenGebruikDefault.Gebruik || vanDelen == null || (!toonEersteLos && regelDisplay.VolledigeContent))
return !string.IsNullOrEmpty(regelDisplay.VersenGebruikDefault.Tekst) ? regelDisplay.VersenGebruikDefault.Tekst : null;
var over = vanDelen.Where(v => v.Nummer.HasValue).Select(v => v.Nummer.Value).ToList();
if (!over.Any())
return null;
var builder = new StringBuilder();
if (toonEersteLos)
{
builder.Append(over.First()).Append(", ");
over.RemoveAt(0);
}
while (over.Any())
{
var nieuweReeks = new List<int> { over.First() };
over.RemoveAt(0);
while (over.Any() && over[0] == nieuweReeks.Last() + 1)
{
nieuweReeks.Add(over[0]);
over.RemoveAt(0);
}
if (nieuweReeks.Count == 1)
builder.Append(nieuweReeks[0]);
else if (nieuweReeks.Count == 2)
builder.Append(string.Join(", ", nieuweReeks));
else
builder.AppendFormat("{0} - {1}", nieuweReeks.First(), nieuweReeks.Last());
builder.Append(", ");
}
return builder.ToString().TrimEnd(',', ' ');
}
示例4: ReverseMod
public static int ReverseMod(int num, int mod)
{
if (Math.Abs(num)>mod)
throw new Exception("Number should be less then mode");
if (num < 0)
num = mod + num;
List<int> dividers = new List<int>();
int rest = 0;
int smaller = num;
int bigger = mod;
while (rest != 1)
{
rest = bigger%smaller;
dividers.Add(bigger/smaller);
bigger = smaller;
smaller = rest;
}
List<int> p = new List<int>();
p.Add(0);
p.Add(1);
foreach (var divider in dividers)
{
p.Add(-divider*p.Last() + p[p.Count()-2]);
}
return p.Last() > 0 ? p.Last() : mod + p.Last();
}
示例5: nettoyerTrajectoire
public void nettoyerTrajectoire()
{
int dirX = 0, dirY = 0, oldDirX = 0, oldDirY = 0; // Directions sur les axes X et Y
List<PositionElement> Sortie = new List<PositionElement>();
foreach (PositionElement p in _Positions)
{
if (Sortie.Count == 0 )
Sortie.Add(p);
else
{
dirX = Math.Sign(p.X - Sortie.Last().X);
dirY = Math.Sign(p.Y - Sortie.Last().Y);
if (dirX != oldDirX || dirY != oldDirY)
{
oldDirX = dirX;
oldDirY = dirY;
Sortie.Add(p);
}
else
{
PositionElement p2 = Sortie[Sortie.Count-1];
p2.X = p.X;
p2.Y = p.Y;
Sortie[Sortie.Count - 1] = p2;
}
}
}
_Positions = Sortie;
}
示例6: Main
static void Main(string[] args)
{
// Task: to convert the Dictionary collection "elements"
//to List with keeping hierarchy of elements
Dictionary<string, string> elements = new Dictionary<string, string>()
{
{"Tissue", "Organ"},
{"Cell", "Cells"},
{"System", "Body"},
{"Cells", "Tissue"},
{"Organ", "System"},
};
List<string> hierarchy = new List<string>();
string first = elements.Keys.First(el => !elements.ContainsValue(el));
hierarchy.Add(first);
while (elements.ContainsKey(hierarchy.Last()))
hierarchy.Add(elements[hierarchy.Last()]);
foreach (var item in hierarchy)
Console.WriteLine(item);
Console.ReadKey();
}
示例7: Read
/// <summary>
/// Reads the specified sub key.
/// </summary>
/// <param name="subKeys">The sub key.</param>
/// <returns></returns>
protected Object Read(string subKeys)
{
Object result = default(Object);
try
{
string[] subKeyNames = subKeys.Split('/');
List<RegistryKey> registryKeys = new List<RegistryKey>();
for (int i = 0; i < subKeyNames.Length - 1; i++)
{
RegistryKey currentRegistryKey = default(RegistryKey);
if (i == 0)
{
currentRegistryKey = Registry.CurrentUser.OpenSubKey(subKeyNames[i]);
}
else
{
currentRegistryKey = registryKeys[i - 1].OpenSubKey(subKeyNames[i]);
}
registryKeys.Add(currentRegistryKey);
if (registryKeys.Last() != null && subKeyNames.Last() != null)
{
result = registryKeys.Last().GetValue(subKeyNames.Last());
}
}
}
catch (Exception ex)
{
log.Error(ex);
}
return result;
}
示例8: Evaluate
public List<GroupedFilesViewModel> Evaluate(int numberOfGroups, string[] directories)
{
var groups = new List<GroupedFilesViewModel>();
var foldersPerGroup = FoldersPerGroupEvaluator.Evaluate(directories.Count(), numberOfGroups);
var i = 0;
for (var g = 0; g < numberOfGroups; g++)
{
var group = new GroupedFilesViewModel { Files = new List<string>() };
group.StartDir = directories[i];
for (var f = 0; f < foldersPerGroup; f++)
{
if (i < directories.Count())
{
group.Files.AddRange(DirectoryDescendentFilesEvaluator.Evaluate(directories[i]).ToList());
i++;
}
}
group.EndDir = directories[i - 1];
groups.Add(group);
}
if (directories.Count() > i)
{
for (var r = i; r < directories.Count(); r++)
{
groups.Last().Files.Add(directories[r]);
groups.Last().EndDir = directories[r];
}
}
return groups;
}
示例9: CreateGapList
/// группирование гэпов; применятся для работы с минутными свечками
public static List<GapList> CreateGapList(List<GapInfo> gaps, int maxGapListLengthDays = 3, int maxGapCount = 50)
{
var result = new List<GapList>();
foreach (var gap in gaps)
{
var requestStart = gap.start;
while (requestStart < gap.end)
{
if(result.Count == 0)
result.Add(new GapList(maxGapListLengthDays, maxGapCount));
var gapList = result.Last();
if (gapList.GetFreeLengthDays() < 0.01) // 0.01 принято за минимально допустимое GetFreeLengthDays
{
result.Add(new GapList(maxGapListLengthDays, maxGapCount));
gapList = result.Last();
}
var requestEnd = requestStart.AddDays(gapList.GetFreeLengthDays()).AddMinutes(-1);
if (requestEnd > gap.end)
requestEnd = gap.end;
gapList.AddGap(new GapInfo {start = requestStart, end = requestEnd});
requestStart = requestEnd.AddMinutes(1);
}
}
return result;
}
示例10: FindBest
public int[] FindBest()
{
var remaining = new HashSet<Point>(_cities);
var first = remaining.First();
var route = new List<Point> { first };
remaining.Remove(first);
var numericRoute = new List<int>{_cities.IndexOf(first)};
var distance = 0.0d;
while (remaining.Any())
{
var shortest = double.MaxValue;
Point next = null;
foreach (var p in remaining)
{
var d = Distance(route.Last(), p);
if (d < shortest)
{
shortest = d;
next = p;
}
}
route.Add(next);
numericRoute.Add(_cities.IndexOf(next));
remaining.Remove(next);
distance += shortest;
}
distance += Distance(route.First(), route.Last());
Console.WriteLine("Distance calculated in closestneighbour: " + distance);
return numericRoute.ToArray();
}
示例11: EMA
/// <summary>
/// Calculates Exponential Moving Average (EMA) indicator
/// </summary>
/// <param name="input">Input signal</param>
/// <param name="period">Number of periods</param>
/// <param name="uisngavg">Start with Average or start with first element</param>
/// <returns>Object containing operation results</returns>
public static EMAResult EMA(IEnumerable<double> input, int period, bool usingavg=true)
{
var returnValues = new List<double>();
double multiplier = (2.0 / (period + 1));
int start = usingavg ? period : 1;
if ( input.Count() >= start)
{
double initialEMA = usingavg ? input.Take(period).Average() : input.First();
returnValues.Add(initialEMA);
var copyInputValues = input.ToList();
for (int i = start; i < copyInputValues.Count; i++)
{
var resultValue = (copyInputValues[i] - returnValues.Last()) * multiplier + returnValues.Last();
returnValues.Add(resultValue);
}
}
var result = new EMAResult()
{
Values = returnValues,
StartIndexOffset = start - 1
};
return result;
}
示例12: StartThreads
private void StartThreads()
{
//How many threads do I need?
int itemCount = ((int)(nudMax.Value - nudMin.Value)) + 1;
int threadCount = itemCount / (int)nudInterval.Value + 1;
threadList = new List<Thread>(threadCount);
//Split up my ranges
int increment = (int)nudInterval.Value;
int maximum = (int)nudMax.Value;
int current = (int)nudMin.Value;
int next = current + increment;
while (current <= maximum)
{
if (next > maximum) next = maximum;
//Create some threads
threadList.Add(new Thread(new ParameterizedThreadStart(FindPrimes)));
threadList.Last().Start(new Limits(current, next));
threadList.Last().IsBackground = true;
current = next + 1;
next = current + increment;
}
//Problem!! If my threads are foreground, we wait here until they are all done.
//If they are background, they all exit once we get here.
//We can solve some of these problems with a threadpool.
}
示例13: ModifLikeProduit
public int ModifLikeProduit(List<string> aData)
{
DataSet DsJson = new DataSet();
MyCo NewCo = new MyCo();
NewCo.UpdateLikeProduit(aData.IndexOf(aData.Last()).ToString(),aData.Last(),ref DsJson);
return aData.IndexOf(aData.Last());
}
示例14: ValidateReordering
private static void ValidateReordering(List<INode> chain1, List<INode> chain2, int closestParentIndex, IDiagInfo diagInfo)
{
var invalidNode1 = GetInvalidNode(chain1, closestParentIndex);
var invalidNode2 = GetInvalidNode(chain2, closestParentIndex);
if (invalidNode1 == null && invalidNode2 == null)
{
return;
}
var fixNode1 = invalidNode1 ?? chain1.Last();
var fixNode2 = invalidNode2 ?? chain2.Last();
var exceptionMessage = $"There is an uncertainty between {chain1.Last()} (a) and {chain2.Last()} (b)" + Environment.NewLine +
$"{GetInvalidateString("a", chain1.Last(), invalidNode1)}{GetInvalidateString("b", chain2.Last(), invalidNode2)}" +
$"To deal with this uncertainty, you can either make {fixNode1} depend on {chain2.Last()} or {fixNode2} depend on {chain1.Last()}";
var tuples = new List<Tuple<IToken, IDiagInfo>>
{
GetNodeTuple(fixNode1),
GetNodeTuple(chain1.Last()),
GetNodeTuple(fixNode2),
GetNodeTuple(chain2.Last())
};
throw new DetailedRegistrationException(exceptionMessage, tuples, diagInfo);
}
示例15: ProcessFile
public IList<Hand> ProcessFile(FileInfo fileInfo)
{
DateTime fileStartDate = DateTime.UtcNow;
string fileStatus = "succes";
var lastImportDate = _dataRepository.GetImportsRepository().GetLastImportFileDate(fileInfo.Name);
IList<Hand> hands = new List<Hand>();
try
{
hands = _parser.Parse(fileInfo.FullName, lastImportDate);
_dataRepository.GetHandsRepository().SaveHandsSqlCommand(hands);
OnNewFileProcessed(new NewFileProcessedEventArgs(fileInfo.Name, hands.Count, hands.Last()));
}
catch (Exception e)
{
fileStatus = "fail : " + e.Message + " " + e.StackTrace;
}
finally
{
DateTime endFileDate = DateTime.UtcNow;
if (hands.Count > 0)
{
var lastHand = hands.Last();
_dataRepository.GetImportsRepository().LogFileImport(fileInfo, fileStartDate, endFileDate, fileStatus, lastHand);
}
}
return hands;
}