本文整理汇总了C#中IList.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Skip方法的具体用法?C# IList.Skip怎么用?C# IList.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.Skip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override dynamic Run(IList<Token> tokens, Context context)
{
/*
1: content to write
2: file object
3: item separator
4: line breack
3: file mode -> w: write, a: append
*/
var arguments = ExtractArguments(tokens.Skip(1).ToArray(), context);
FileObject fileObject;
string separator = ",", lineBreack = "\r\n";
var rhs = recurse.Run(tokens.Skip(2).Take(1).ToArray(), context);
fileObject = recurse.Run(tokens.Skip(4).Take(1).ToArray(), context);
if (arguments.Count() >= 6)
separator = arguments[5].Value.ExtractStringValue();
if (arguments.Count() >= 7)
lineBreack = arguments[6].Value.ExtractStringValue();
context.Core.WriteToFile(rhs, fileObject, separator, lineBreack);
return null;
}
示例2: CreateTupleTypeList
/// <summary>
/// Creates type list for nested tuples.
/// </summary>
/// <param name="itemTypes">The type list of tuple items, in order.</param>
/// <returns>
/// The type list for nested tuples.
/// The order is from outer to inner.
/// </returns>
public static List<Type> CreateTupleTypeList( IList<Type> itemTypes )
{
var itemTypesStack = new Stack<List<Type>>( itemTypes.Count / 7 + 1 );
for ( int i = 0; i < itemTypes.Count / 7; i++ )
{
itemTypesStack.Push( itemTypes.Skip( i * 7 ).Take( 7 ).ToList() );
}
if ( itemTypes.Count % 7 != 0 )
{
itemTypesStack.Push( itemTypes.Skip( ( itemTypes.Count / 7 ) * 7 ).Take( itemTypes.Count % 7 ).ToList() );
}
var result = new List<Type>( itemTypesStack.Count );
while ( 0 < itemTypesStack.Count )
{
var itemTypesStackEntry = itemTypesStack.Pop();
if ( 0 < result.Count )
{
itemTypesStackEntry.Add( result.Last() );
}
var tupleType = Type.GetType( "System.Tuple`" + itemTypesStackEntry.Count, true ).MakeGenericType( itemTypesStackEntry.ToArray() );
result.Add( tupleType );
}
result.Reverse();
return result;
}
示例3: Match
public bool Match(IList<Token> tokens, HandlerRegistry registry)
{
var tokenIndex = 0;
foreach (var pattern in _patterns)
{
var isOptional = pattern.IsOptional;
var isRequired = !isOptional;
var thereAreNoMoreTokens = tokenIndex == tokens.Count;
if (pattern is TagPattern)
{
var match = tokenIndex < tokens.Count &&
tokens[tokenIndex].IsTaggedAs((pattern as TagPattern).TagType);
if (match == false && isRequired)
{
return false;
}
if (match)
{
tokenIndex++;
}
}
else if (pattern is RepeatPattern)
{
var repetition = pattern as RepeatPattern;
int advancement;
var match = repetition.Match(tokens.Skip(tokenIndex).ToList(), out advancement);
if (match == false && isRequired)
{
return false;
}
if (match)
{
tokenIndex += advancement;
}
}
else if (pattern is HandlerTypePattern)
{
if (isOptional && thereAreNoMoreTokens)
{
return true;
}
var subHandlers = registry.GetHandlers((pattern as HandlerTypePattern).Type);
foreach (var handler in subHandlers)
{
if (handler.Match(tokens.Skip(tokenIndex).ToList(), registry))
{
return true;
}
}
}
}
if (tokenIndex != tokens.Count)
{
return false;
}
return true;
}
示例4: Run
public override dynamic Run(IList<Token> tokens, Context context)
{
ExpectTokens(tokens, 4);
if (tokens[1].Type != TokenType.OpenPar || tokens[3].Type != TokenType.Comma || tokens[5].Type != TokenType.ClosedPar)
throw new Exception("Invalid syntax.");
var value = recurse.Run(tokens.Skip(2).Take(1).ToArray(), context);
var xpath = recurse.Run(tokens.Skip(4).Take(1).ToArray(), context);
return context.Core.Find(value, xpath);
}
示例5: Run
public override dynamic Run(IList<Token> tokens, Context context)
{
ExpectTokens(tokens, 1);
var rhs = recurse.Run(tokens.Skip(2).ToArray(), context);
var separator = recurse.Run(tokens.Skip(4).ToArray(), context);
string lineEnd = "";
if (tokens.Count >= 6)
lineEnd = recurse.Run(tokens.Skip(6).ToArray(), context);
context.Core.PrintList(rhs, separator, lineEnd);
return null;
}
示例6: 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;
}
示例7: 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);
}
示例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: ExportExcel
public void ExportExcel(IList<dynamic> items, string fileName)
{
using (var excelPackage = new ExcelPackage(new FileStream(fileName, FileMode.CreateNew)))
{
var currentIndex = 0;
var sheetIndex = 1;
do
{
var take = Math.Min(1000000, items.Count - currentIndex);
var currentSet = items.Skip(currentIndex).Take(take).ToList();
currentIndex += currentSet.Count;
var sheet = excelPackage.Workbook.Worksheets.Add("Sheet " + sheetIndex);
var arrayData = new List<object[]>();
foreach (var item in currentSet)
{
arrayData.Add(((IDictionary<string, object>)item).Values.ToArray());
}
sheet.Cells["A1"].LoadFromArrays(arrayData);
sheetIndex++;
excelPackage.Save();
}
while (currentIndex < items.Count);
}
}
示例10: Filter
public IList<DepthPointEx> Filter(IList<DepthPointEx> points)
{
IList<DepthPointEx> result = new List<DepthPointEx>();
if (points.Count > 0)
{
var point = new DepthPointEx(points.First());
result.Add(point);
foreach (var currentSourcePoint in points.Skip(1))
{
if (!PointsAreClose(currentSourcePoint, point))
{
point = new DepthPointEx(currentSourcePoint);
result.Add(point);
}
}
if (result.Count > 1)
{
CheckFirstAndLastPoint(result);
}
}
return result;
}
示例11: FindAllAverages
public IEnumerable<Double> FindAllAverages(IList<double> values, int windowSize)
{
//Checking for errors
if(windowSize > values.Count)
throw new ValueCountLessThanWindowException();
if (windowSize < 0)
throw new BadWindowException();
if (values.Count == 0)
throw new ValuesCountException();
var cumulativeAverageArray = new double[values.Count];
var currentAverage = 0.0;
for (var i = 0; i < values.Count; i++)
{
var convertedIndexToCounterFromIndex = i + 1;
if (convertedIndexToCounterFromIndex <= windowSize && i != 0) // handles greater than 0, but less than window size
{
currentAverage = (((currentAverage * i) + values[i]) / convertedIndexToCounterFromIndex);
}
else if (convertedIndexToCounterFromIndex <= windowSize) // handles 0 case
{
currentAverage = (((currentAverage * i) + values[i]) / convertedIndexToCounterFromIndex);
}
else // https://en.wikipedia.org/wiki/Moving_average //handles greater than 0 and greater than window size
{
currentAverage = ((values.Skip(convertedIndexToCounterFromIndex - windowSize).Take(windowSize).Sum()) / windowSize);
}
cumulativeAverageArray[i] = currentAverage;
}
return cumulativeAverageArray;
}
示例12: Filter
public IList<Point> Filter(IList<Point> points)
{
IList<Point> result = new List<Point>();
if (points.Count == 0)
{
return result;
}
var point = new Point(points.First());
result.Add(point);
foreach (var currentSourcePoint in points.Skip(1))
{
if (!this.DistanceIsTooSmall(currentSourcePoint, point))
{
point = new Point(currentSourcePoint);
result.Add(point);
}
}
if (this.checkBoundary && result.Count > 1)
{
CheckFirstAndLastPoint(result);
}
return result;
}
示例13: Call
public void Call(IList<IValue> args, VM vm, SourceInfo info)
{
int argCount = args.Count;
if (argCount < mParamCount ||
argCount > mParamCount && !mAllowRest && !mAllowKeys)
{
throw new RheaException(
this.WrongNumberOfArguments(mParamCount, argCount), info
);
}
var dict = new Dictionary<IValue, IValue>();
if (mAllowKeys)
{
foreach (IValue arg in args.Skip(mParamCount))
{
ValueArray pair = arg as ValueArray;
if (pair == null || pair.Value.Count != 2)
{
throw new RheaException(
"keyword arguments should occur pairwise", info
);
}
dict.Add(pair.Value[0], pair.Value[1]);
}
}
var newArgs = new Arguments(args, dict);
mSubrValue(newArgs, vm, info);
}
示例14: 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;
}
示例15: mergeFirstTwoFunctions
private static IList<MembershipFunction> mergeFirstTwoFunctions(IList<MembershipFunction> msfs)
{
var combined = combine(msfs[0], msfs[1]);
var newMsfs = new List<MembershipFunction> {combined};
newMsfs.AddRange(msfs.Skip(2));
return newMsfs;
}