本文整理汇总了C#中List.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# List.Skip方法的具体用法?C# List.Skip怎么用?C# List.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Skip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFirstSeason
public Season CreateFirstSeason(Game game, List<Team> teams, IUnitOfWorkRepository repository)
{
// First check the number of teams can be evenly divided into the number of leagues.
bool teamsOk = teams.Count % Constants.HowManyLeagues == 0;
if (!teamsOk)
{
throw new Exception($"The number of teams must be divided by {Constants.HowManyLeagues}");
}
var newSeasonInfo = new NewSeasonInfo { Game = game, SeasonNumber = 0 };
// Divide all teams between the four leagues based on the team rating.
teams.Sort((team1, team2) => team2.Rating.CompareTo(team1.Rating));
int countTeamsPerLeague = teams.Count / Constants.HowManyLeagues;
newSeasonInfo.TeamsLeague1 = teams.Take(countTeamsPerLeague).ToList();
newSeasonInfo.TeamsLeague2 = teams.Skip(countTeamsPerLeague).Take(countTeamsPerLeague).ToList();
newSeasonInfo.TeamsLeague3 = teams.Skip(countTeamsPerLeague * 2).Take(countTeamsPerLeague).ToList();
newSeasonInfo.TeamsLeague4 = teams.Skip(countTeamsPerLeague * 3).ToList();
// The teams have been sorted on rating, so given them an initial league table position.
AssignInitialLeagueTablePosition(teams);
// In the first season there are no champion and cup winner yet, so pick the two best teams.
newSeasonInfo.NationalChampion = teams[0];
newSeasonInfo.NationalCupWinner = teams[1];
// Now all teams have been placed in the right leagues, so create match schedules for all competitions.
var seasonAndCompetitionSchedules = CreateSeasonAndCompetitionSchedules(newSeasonInfo);
// Insert the season and all competition schedules.
var season = InsertSeasonAndCompetitionSchedule(repository, seasonAndCompetitionSchedules);
return season;
}
示例2: Select_Finds_FirstToSatisfyAllConstraints
public void Select_Finds_FirstToSatisfyAllConstraints()
{
var mockery = new MockRepository();
var constraint1 = mockery.StrictMock<IResidentConstraint>();
var constraint2 = mockery.StrictMock<IResidentConstraint>();
var selector = new ResidentSelector();
selector.Constraints.Clear();
selector.Constraints.Add(constraint1);
selector.Constraints.Add(constraint2);
var residents = new List<Resident> { new Resident(), new Resident(), new Resident() };
var shift = new Shift(DateTime.Today, DateTime.Today, DateTime.Today);
using (mockery.Record()) {
SetupResult.For(constraint1.Assignable(residents.First(), shift)).Return(false);
SetupResult.For(constraint2.Assignable(residents.First(), shift)).Return(true);
SetupResult.For(constraint1.Assignable(residents.Skip(1).First(), shift)).Return(true);
SetupResult.For(constraint2.Assignable(residents.Skip(1).First(), shift)).Return(false);
SetupResult.For(constraint1.Assignable(residents.Skip(2).First(), shift)).Return(true);
SetupResult.For(constraint2.Assignable(residents.Skip(2).First(), shift)).Return(true);
}
using (mockery.Playback()) {
Assert.AreEqual(residents.Skip(2).First(), selector.Select(residents, shift));
}
}
示例3: ListMatches
public static List<List<Tuple<Teams, Teams>>> ListMatches(List<Teams> listTeam)
{
var result = new List<List<Tuple<Teams, Teams>>>();
int numDays = (listTeam.Count - 1);
int halfSize = listTeam.Count / 2;
var teams = new List<Teams>();
teams.AddRange(listTeam.Skip(halfSize).Take(halfSize));
teams.AddRange(listTeam.Skip(1).Take(halfSize - 1).ToArray().Reverse());
int teamsSize = teams.Count;
for (int day = 0; day < numDays; day++)
{
var round = new List<Tuple<Teams, Teams>>();
int teamIdx = day % teamsSize;
round.Add(new Tuple<Teams, Teams>(teams[teamIdx], listTeam[0]));
for (int idx = 1; idx < halfSize; idx++)
{
int firstTeam = (day + idx) % teamsSize;
int secondTeam = (day + teamsSize - idx) % teamsSize;
round.Add(new Tuple<Teams, Teams>(teams[firstTeam], teams[secondTeam]));
}
result.Add(round);
}
return result;
}
示例4: SortGlobalSections
private void SortGlobalSections(List<Line> lines)
{
var begin = lines
.Where(line => line.Content.Trim().StartsWith("GlobalSection(", StringComparison.OrdinalIgnoreCase))
.ToList();
var sections = begin.Select(line => new
{
Begin = line,
Entries = lines.Skip(line.Index + 1)
.TakeWhile(x => !x.Content.Trim().Equals("EndGlobalSection", StringComparison.OrdinalIgnoreCase))
.OrderBy(x => x.Content)
.ToList(),
End = lines.Skip(line.Index + 1)
.First(x => x.Content.Trim().Equals("EndGlobalSection", StringComparison.OrdinalIgnoreCase))
}).ToList();
foreach (var section in sections)
{
lines.RemoveRange(section.Begin.Index + 1, section.Entries.Count);
lines.InsertRange(section.Begin.Index + 1, section.Entries);
}
ResetIndexes(lines);
}
示例5: ReceiveData
private void ReceiveData(List<byte> data, IReadState readState, Action<FrameType, byte[]> processFrame)
{
while (data.Count >= 2)
{
bool isFinal = (data[0] & 128) != 0;
var frameType = (FrameType)(data[0] & 15);
int length = (data[1] & 127);
var reservedBits = (data[0] & 112);
if (reservedBits != 0)
{
return;
}
int index = 2;
int payloadLength;
if (length == 127)
{
if (data.Count < index + 8)
return; //Not complete
payloadLength = data.Skip(index).Take(8).ToArray().ToLittleEndianInt();
index += 8;
}
else if (length == 126)
{
if (data.Count < index + 2)
return; //Not complete
payloadLength = data.Skip(index).Take(2).ToArray().ToLittleEndianInt();
index += 2;
}
else
{
payloadLength = length;
}
if (data.Count < index + 4)
return; //Not complete
if (data.Count < index + payloadLength)
return; //Not complete
IEnumerable<byte> payload = data
.Skip(index)
.Take(payloadLength)
.Select(b => b);
readState.Data.AddRange(payload);
data.RemoveRange(0, index + payloadLength);
if (frameType != FrameType.Continuation)
readState.FrameType = frameType;
if (!isFinal || !readState.FrameType.HasValue) continue;
byte[] stateData = readState.Data.ToArray();
FrameType? stateFrameType = readState.FrameType;
readState.Clear();
processFrame(stateFrameType.Value, stateData);
}
}
示例6: RunArgs
public static void RunArgs (List<String> args) {
if (args!=null && args.Count>0) {
var x = args[0].ToUpper();
if (x=="XTCLI") { App.ExeType="CLI"; App.CommandClass="XT.App+CLI+Commands"; args=args.Skip(1).ToList(); }
if (x=="XTGUI") { App.ExeType="GUI"; App.CommandClass="XT.App+GUI+Commands"; args=args.Skip(1).ToList(); }
if (x=="XTSVC") { App.ExeType="SVC"; App.CommandClass="XT.App+SVC+Commands"; args=args.Skip(1).ToList(); }
}
//if (args[0].Contains(".Commands")) { App.CommandClass = args[0]; args = args.Skip(1).ToList(); }
RunCommand(App.CommandClass,args);
}
示例7: PriceModel
public PriceModel(List<double> deltas, double tailPercent)
{
this.tailPercent = tailPercent;
// отсечь 0.2% + 0.2% результатов "справа" и "слева" как "хвосты"
var tailCount = (int)(deltas.Count * this.tailPercent / 100);
var bodyCount = deltas.Count - tailCount * 2;
tailLeft = new ValueRange(deltas.Take(tailCount).ToArray(), StepsPerTail);
body = new ValueRange(deltas.Skip(tailCount).Take(bodyCount).ToArray(), StepsPerBody);
tailRight = new ValueRange(deltas.Skip(tailCount + bodyCount).ToArray(), StepsPerTail);
}
示例8: SelecionarCotacoesPorJanelamento
/// <summary>
/// Retorna uma lista de KeyValuePair, onde a chave são os valores de input e o seu valor correspondente são os valores de output
/// </summary>
/// <param name="dados"></param>
/// <param name="janelaEntrada">tamanho do input</param>
/// <param name="janelaSaida">tamanho do output</param>
/// <param name="considerarSaidasComoEntradas">se verdadeiro, teremos 'dados.Count / janelaEntrada' registros como saida, caso contrario, 'dados.Count / (janelaEntrada + janelaSaida)' </param>
/// <returns></returns>
public static List<KeyValuePair<double[], double[]>> SelecionarCotacoesPorJanelamento(List<double> dados, int janelaEntrada, int janelaSaida, bool considerarSaidasComoEntradas)
{
/*Cria um mapeamento de entradas para saida com o janelamento informado*/
List<KeyValuePair<double[], double[]>> dadosPorJanelamento = new List<KeyValuePair<double[], double[]>>();
for (int i = 0; i < dados.Count - (janelaEntrada + janelaSaida); i += janelaEntrada + (considerarSaidasComoEntradas ? 0 : janelaSaida))
{
dadosPorJanelamento.Add(new KeyValuePair<double[], double[]>(dados.Skip(i).Take(janelaEntrada).ToArray(), dados.Skip(i + janelaEntrada).Take(janelaSaida).ToArray()));
}
/*Cria um mapeamento de entradas para saida com o janelamento informado*/
return dadosPorJanelamento;
}
示例9: Select_Finds_Resident_Associated_With_RotationShift_First
public void Select_Finds_Resident_Associated_With_RotationShift_First()
{
var rotationShift = new RotationShift(BitwiseDayOfWeek.Monday | BitwiseDayOfWeek.Tuesday, TimeConstants.StartOfDay12HourDay, TimeConstants.EndOfDay12HourDay);
var shifts = new ShiftFactory().Create(new List<RotationShift> { rotationShift }, new DateTime(2012, 12, 3), new DateTime(2012, 12, 4)).ToList();
var residents = new List<Resident> { new Resident(), new Resident() };
shifts.First().Resident = residents.Skip(1).First();
var selector = new ResidentSelector();
selector.Constraints.Clear();
Assert.AreEqual(residents.Skip(1).First(), selector.Select(residents, shifts.Skip(1).First()));
}
示例10: GetDeviceList
public static iDeviceError GetDeviceList(out List<IDevice> deviceList)
{
List<IDevice> devices = new List<IDevice>();
IntPtr devicesPtr;
iDeviceError returnCode = SearchForDevices(out devices, out devicesPtr);
devices = devices.Where(x => devices.Skip(devices.IndexOf(x) + 1).Count(y => y.Udid == x.Udid) == 0).ToList();
deviceList = new List<IDevice>();
foreach (IDevice currDevice in devices)
{
IntPtr lockdownService;
IntPtr lockdownClient;
Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice.Handle, out lockdownClient, out lockdownService);
XDocument deviceProperties;
lockdownReturnCode = Lockdown.GetProperties(lockdownClient, out deviceProperties);
IEnumerable<XElement> keys = deviceProperties.Descendants("dict").Descendants("key");
deviceList.Add(new IDevice(
IntPtr.Zero,
keys.Where(x => x.Value == "UniqueDeviceID").Select(x => (x.NextNode as XElement).Value).FirstOrDefault(),
keys.Where(x => x.Value == "SerialNumber").Select(x => (x.NextNode as XElement).Value).FirstOrDefault(),
keys.Where(x => x.Value == "DeviceName").Select(x => (x.NextNode as XElement).Value).FirstOrDefault(),
keys.Where(x => x.Value == "ProductType").Select(x => (x.NextNode as XElement).Value).FirstOrDefault()
));
// Freeing
lockdownReturnCode = Lockdown.FreeService(lockdownService);
lockdownReturnCode = Lockdown.FreeClient(lockdownClient);
returnCode = FreeDevice(currDevice.Handle);
}
return returnCode;
}
示例11: Solve
private static string Solve(string[] words)
{
string prefix = string.Empty;
List sorted = new List(words);
while (true) {
sorted = sorted.OrderBy(x => x).ToList();
if (sorted.Count == 0) break;
string pr = sorted.First();
string sf = sorted.Skip(1)
.Where(a => a.StartsWith(pr))
.Select(s => s.Substring(pr.Length))
.Where(s => !string.IsNullOrEmpty(s))
.OrderBy(x => x + pr)
.FirstOrDefault();
if (string.Compare(pr + pr, pr + sf) < 0)
sf = null;
prefix += pr + sf;
sorted.Remove(pr + sf);
}
return prefix;
}
示例12: Write
public void Write(Storage storage, string fileSpecificPath, string fileWordsPath)
{
var bitmap = new List<byte>();
var words = GenerateWordsStringAndBitmap(bitmap, storage);
if (words == null || words == "")
return;
var bytemap = new List<byte>();
while (bitmap.Count > 0)
{
var oneByte = bitmap.Take(8).ToList();
bitmap = bitmap.Skip(8).ToList();
bytemap.Add(oneByte.Aggregate((byte)0, (result, bit) => (byte)((result << 1) | bit)));
}
using (var streamWriter = new StreamWriter(fileWordsPath))
{
streamWriter.Write(words);
}
using (var fileStream = new FileStream(fileSpecificPath, FileMode.OpenOrCreate))
{
fileStream.Write(bytemap.ToArray(), 0, bytemap.Count);
fileStream.Close();
}
}
示例13: ExecuteAddRemove
private bool ExecuteAddRemove(HaloTag tag, List<string> args)
{
if (args.Count < 3)
return false;
var dependencies = args.Skip(2).Select(a => ArgumentParser.ParseTagIndex(_cache, a)).ToList();
if (dependencies.Count == 0 || dependencies.Any(d => d == null))
return false;
if (args[0] == "add")
{
foreach (var dependency in dependencies)
{
if (tag.Dependencies.Add(dependency.Index))
Console.WriteLine("Added dependency on tag {0:X8}.", dependency.Index);
else
Console.Error.WriteLine("Tag {0:X8} already depends on tag {1:X8}.", tag.Index, dependency.Index);
}
}
else
{
foreach (var dependency in dependencies)
{
if (tag.Dependencies.Remove(dependency.Index))
Console.WriteLine("Removed dependency on tag {0:X8}.", dependency.Index);
else
Console.Error.WriteLine("Tag {0:X8} does not depend on tag {1:X8}.", tag.Index, dependency.Index);
}
}
using (var stream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite))
_cache.UpdateTag(stream, tag);
return true;
}
示例14: Statistics
public Statistics(IEnumerable<double> values)
{
list = values.ToList();
N = list.Count;
if (N == 0)
throw new InvalidOperationException("StatSummary: Sequence contains no elements");
list.Sort();
if (N == 1)
Q1 = Median = Q3 = list[0];
else
{
Func<IList<double>, double> getMedian = x => x.Count % 2 == 0
? (x[x.Count / 2 - 1] + x[x.Count / 2]) / 2
: x[x.Count / 2];
Median = getMedian(list);
Q1 = getMedian(list.Take(N / 2).ToList());
Q3 = getMedian(list.Skip((N + 1) / 2).ToList());
}
Min = list.First();
Mean = list.Average();
Max = list.Last();
InterquartileRange = Q3 - Q1;
LowerFence = Q1 - 1.5 * InterquartileRange;
UpperFence = Q3 + 1.5 * InterquartileRange;
Outliers = list.Where(IsOutlier).ToArray();
StandardDeviation = N == 1 ? 0 : Math.Sqrt(list.Sum(d => Math.Pow(d - Mean, 2)) / (N - 1));
StandardError = StandardDeviation / Math.Sqrt(N);
ConfidenceInterval = new ConfidenceInterval(Mean, StandardError);
Percentiles = new PercentileValues(list);
}
示例15: Optimize
public static List<FortData> Optimize(FortData[] pokeStops, LatLong latlng, GMapOverlay routeOverlay)
{
List<FortData> optimizedRoute = new List<FortData>(pokeStops);
// NN
FortData NN = FindNN(optimizedRoute, latlng.Latitude, latlng.Longitude);
optimizedRoute.Remove(NN);
optimizedRoute.Insert(0, NN);
for (int i = 1; i < pokeStops.Length; i++)
{
NN = FindNN(optimizedRoute.Skip(i), NN.Latitude, NN.Longitude);
optimizedRoute.Remove(NN);
optimizedRoute.Insert(i, NN);
Visualize(optimizedRoute, routeOverlay);
}
// 2-Opt
bool isOptimized;
do
{
optimizedRoute = Optimize2Opt(optimizedRoute, out isOptimized);
Visualize(optimizedRoute, routeOverlay);
}
while (isOptimized);
return optimizedRoute;
}