本文整理汇总了C#中IList.Take方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Take方法的具体用法?C# IList.Take怎么用?C# IList.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.Take方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
public Span Handle(IList<Token> tokens, Options options)
{
RepeaterMonthName month = null;
int day = 0;
IList<Token> remainingTokens = null;
if (tokens.Count > 3)
{
month = tokens[2].GetTag<RepeaterMonthName>();
day = tokens[3].GetTag<ScalarDay>().Value;
remainingTokens = tokens.Take(2).ToList();
}
else
{
month = tokens[1].GetTag<RepeaterMonthName>();
day = tokens[2].GetTag<ScalarDay>().Value;
remainingTokens = tokens.Take(1).ToList();
}
var now = options.Clock();
if (Time.IsMonthOverflow(now.Year, (int)month.Value, day))
{
return null;
}
return Utils.HandleMD(month, day, remainingTokens, options);
}
示例2: FindPositionPart
public static string FindPositionPart(IList<string> parts, int cursorPosition, out int foundPartsIndex, out int cursorInPartPosition)
{
cursorInPartPosition = 0;
var partsComplete = parts.Aggregate(String.Empty, (aggr, s) => aggr + s);
for (int i = 0; i < parts.Count(); i++) {
var partsLower = parts.Take(i).Aggregate(String.Empty, (aggr, s) => aggr + s);
var partsUpper = parts.Take(i + 1).Aggregate(String.Empty, (aggr, s) => aggr + s);
var b = partsLower.Length;
var t = partsUpper.Length;
if ((cursorPosition >= b && cursorPosition < t) || partsUpper == partsComplete) {
if (parts[i] == WorkDayParser.itemSeparator.ToString() || parts[i] == WorkDayParser.hourProjectInfoSeparator.ToString()) {
// cursor left of separator
foundPartsIndex = i - 1;
var prevPart = parts.ElementAt(foundPartsIndex);
// find out where in the found part the cursor is, need to use prevpart an its length
cursorInPartPosition = prevPart.Length;
return prevPart;
} else {
// find out where in the found part the cursor is
cursorInPartPosition = cursorPosition - b;
foundPartsIndex = i;
return parts.ElementAt(i);
}
}
}
// not found
foundPartsIndex = -1;
return String.Empty;
}
示例3: GetFormation
public static string GetFormation(IList<PlayerGameweekPerformance> performances)
{
var defenders = performances.Take(11).Count(p => p.Position == Position.Defender);
var midfielders = performances.Take(11).Count(p => p.Position == Position.Midfielder);
var forwards = performances.Take(11).Count(p => p.Position == Position.Forward);
return string.Format("{0}-{1}-{2}", defenders, midfielders, forwards);
}
示例4: GetFibLikeSequence
private static IList<ulong> GetFibLikeSequence(IList<ulong> seedSequence, int length)
{
IList<ulong> sequence = new List<ulong>();
int count = seedSequence.Count();
if (length <= count)
{
sequence = seedSequence.Take((int)length).ToList();
}
else
{
sequence = seedSequence;
for (int i = count; i < length; i++)
{
ulong num = 0;
for (int j = 0; j < count; j++)
{
num += sequence[sequence.Count - 1 - j];
}
sequence.Add(num);
}
}
return sequence;
}
示例5: Match
public override MatchResult Match(IList<Pattern> left, IEnumerable<Pattern> collected = null)
{
var coll = collected ?? new List<Pattern>();
var sresult = SingleMatch(left);
var match = sresult.Match;
if (match == null)
{
return new MatchResult(false, left, coll);
}
var left_ = new List<Pattern>();
left_.AddRange(left.Take(sresult.Position));
left_.AddRange(left.Skip(sresult.Position + 1));
var sameName = coll.Where(a => a.Name == Name).ToList();
if (Value != null && (Value.IsList || Value.IsOfTypeInt))
{
var increment = new ValueObject(1);
if (!Value.IsOfTypeInt)
{
increment = match.Value.IsString ? new ValueObject(new [] {match.Value}) : match.Value;
}
if (sameName.Count == 0)
{
match.Value = increment;
var res = new List<Pattern>(coll) {match};
return new MatchResult(true, left_, res);
}
sameName[0].Value.Add(increment);
return new MatchResult(true, left_, coll);
}
var resColl = new List<Pattern>();
resColl.AddRange(coll);
resColl.Add(match);
return new MatchResult(true, left_, resColl);
}
示例6: 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;
}
}
}
示例7: FaroShuffle
/// <summary>
/// Returns a Faro shuffled list.
/// The initial list is split in half. A new list is created by alternately adding each item from the half-lists to it.
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public static IList<string> FaroShuffle(IList<string> list)
{
if (list.Count == 0)
return list;
var items = list.Count;
//First half needs to greater by 1, or equal to the second half for this to work right
int firstHalfSize;
if (list.Count % 2 == 0)
firstHalfSize = list.Count / 2;
else
firstHalfSize = list.Count / 2 + 1;
//Split in two halfs
IList<string> firstHalf = list.Take(firstHalfSize).ToList();
IList<string> secondHalf = list.Skip(firstHalfSize).Take(list.Count - firstHalfSize).ToList();
IList<string> result = new List<string>();
for (int i = 0, skip = 0; i < items; i = i + 2, skip++)
{
var item = firstHalf.Skip(skip).FirstOrDefault();
if (item != null)
result.Add(item);
item = secondHalf.Skip(skip).FirstOrDefault();
if (item != null)
result.Add(item);
}
return result;
}
示例8: 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();
}
示例9: ValidateLinks
public IEnumerable<PageLinksValidationResult> ValidateLinks(IList<DocumentationPage> pages)
{
var results = new ConcurrentBag<PageLinksValidationResult>();
var p = new List<DocumentationPage>[2];
var half = pages.Count / 2;
p[0] = pages.Take(half).ToList();
p[1] = pages.Skip(half).ToList();
Parallel.For(
0,
2,
i =>
{
using (var client = new HttpClient())
{
var pagesToCheck = p[i];
foreach (var page in pagesToCheck)
results.Add(ValidatePageLinks(client, page, pages));
}
});
return results;
}
示例10: UpdateSearchResults
private static void UpdateSearchResults(IList<SearchResult> searchResults, XPathWorkbench workbench)
{
foreach(var searchResult in searchResults.Take(XPathWorkbench.MaxSearchResultCount))
{
workbench.SearchResults.Add(searchResult);
}
workbench.UpdateSearchResultText(searchResults);
}
示例11: Execute
public void Execute(IList<IRecord> records, IList<IWorkItemTarget> targets)
{
String body = TemplateEngine.EvaluateTemplate(records, _body);
String subject = TemplateEngine.EvaluateTemplate(records.Take(1).ToList(), _subject);
String[] recipient = targets.Select(x => x.Evaluate(records[0])).ToArray();
((SmtpDeliverySystem)DeliverySystem).SendEmail(recipient, subject, body);
}
示例12: BuildFirstSeason
private IList<TripleExponentialEntry> BuildFirstSeason(IList<SeasonalIndex> seasonalIndices)
{
return seasonalIndices.Take(_periodsPerSeason).Select(i => new TripleExponentialEntry
{
Ft = 0,
Tt = 0,
St = i.PeriodSeasonalComponent,
Forecast = 0
}).ToList();
}
示例13: ForecastSeries
private static IEnumerable<double> ForecastSeries(IList<double> series, IEnumerable<IEnumerable<int>> indices, IEnumerable<int> radiuses, int period, int startForecastingFrom)
{
var indicesList = indices.Select(x => x.ToList()).ToList();
var radiusesList = radiuses.ToList();
var trainingSeries = series.Take(startForecastingFrom).ToList();
foreach (var value in series.Skip(startForecastingFrom))
{
trainingSeries.Add(value);
yield return Forecast(trainingSeries, indicesList, radiusesList, period);
}
}
示例14: ReplaceAnonymousType
private static void ReplaceAnonymousType(
IList<SymbolDisplayPart> list,
INamedTypeSymbol anonymousType,
IEnumerable<SymbolDisplayPart> parts)
{
var index = list.IndexOf(p => anonymousType.Equals(p.Symbol));
if (index >= 0)
{
var result = list.Take(index).Concat(parts).Concat(list.Skip(index + 1)).ToList();
list.Clear();
list.AddRange(result);
}
}
示例15: Build
public Grid Build(IList<IPanelItem> items)
{
var grid = new Grid();
var i = 1;
while (!items.IsNullOrEmpty())
{
grid.Blocks.Add(GenerateBlock(items.Take(i)));
items = items.Skip(i).ToList();
if (items.IsNullOrEmpty())
break;
i = i == 1 ? 4 : 1;
grid.Blocks.Add(GenerateBlock(items.Take(i)));
items = items.Skip(i).ToList();
}
return grid;
}