本文整理汇总了C#中IEnumerable.Take方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.Take方法的具体用法?C# IEnumerable.Take怎么用?C# IEnumerable.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.Take方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseObject
/// <summary>
/// Parses the object.
/// </summary>
/// <param name="relativePaths">The relative paths. <example>{"site1","themes","default"}</example></param>
/// <returns>the remaining paths. <example>{"site1"}</example></returns>
internal override IEnumerable<string> ParseObject(IEnumerable<string> relativePaths)
{
var index = Array.LastIndexOf(relativePaths.Select(it => it.ToLower()).ToArray(), PATH_NAME.ToLower());
relativePaths = relativePaths.Take(index + 2);
this.Name = relativePaths.Last();
return relativePaths.Take(relativePaths.Count() - 2);
}
示例2: Replace
public static IEnumerable<byte> Replace(IEnumerable<byte> input, IEnumerable<byte> from, IEnumerable<byte> to)
{
var fromEnumerator = from.GetEnumerator();
fromEnumerator.MoveNext();
int match = 0;
foreach (var data in input)
{
if (data == fromEnumerator.Current)
{
match++;
if (fromEnumerator.MoveNext()) { continue; }
foreach (byte d in to) { yield return d; }
match = 0;
fromEnumerator.Reset();
fromEnumerator.MoveNext();
continue;
}
if (0 != match)
{
foreach (byte d in from.Take(match)) { yield return d; }
match = 0;
fromEnumerator.Reset();
fromEnumerator.MoveNext();
}
yield return data;
}
if (0 != match)
{
foreach (byte d in from.Take(match)) { yield return d; }
}
}
示例3: TryEliminate
bool TryEliminate (IEnumerable<string> methods, int chunkSize) {
var count = methods.Count ();
if (chunkSize < 1 || chunkSize > count)
throw new Exception ("I can't do math.");
var numChunks = (count + chunkSize - 1) / chunkSize;
foreach (var i in EliminationOrder (numChunks)) {
var firstIndex = i * chunkSize;
var lastPlusOneIndex = (i + 1) * chunkSize;
var methodsLeft = methods.Take (firstIndex).Concat (methods.Skip (lastPlusOneIndex));
if (chunkSize == 1)
Console.WriteLine ("Running without method at position {0}", firstIndex);
else
Console.WriteLine ("Running without methods at positions {0} to {1}", firstIndex, lastPlusOneIndex - 1);
var success = RunWithMethods (methodsLeft);
Console.WriteLine ("Crashed: {0}", !success);
if (!success) {
Console.WriteLine ("Eliminating further from {0} methods.", methodsLeft.Count ());
return EliminationStep (methodsLeft);
}
}
return false;
}
示例4: SplitDic
public static void SplitDic(IEnumerable<int> dic, int step)
{
//SplitList =new ConcurrentQueue<List<int>>();
// ConcurrentQueue<List<int>> SplitList = new ConcurrentQueue<List<int>>();
if (dic.Count() > step)
{
IEnumerable<int> keyvaluelist = dic.Take(step);
List<int> newdic = new List<int>();
foreach (int s in keyvaluelist)
{
newdic.Add(s);
}
SplitList.Enqueue(newdic);
SplitDic(dic.Skip(step), step);
}
else
{
List<int> newdic = new List<int>();
foreach (int s in dic)
{
newdic.Add(s);
}
SplitList.Enqueue(newdic);
}
//return SplitList;
}
示例5: filteRealtimeReview
public List<RealtimeReview> filteRealtimeReview(TNS.Metadata.Query.QRealtimeReview condition, IEnumerable<RealtimeReview> result)
{
try
{
result = result.Where(x => x.hotelId == condition.hotelId.ToString()).Select(x => x);
if (!string.IsNullOrEmpty(condition.checkin))
{
if (condition.isDateRange)
{
result = result.Where(i => i.startDate.ConvertToDateTime().CompareTo(condition.checkin.ConvertToDateTime()) >= 0).Select(i => i);
}
else
{
result = result.Where(i => i.startDate.ConvertToDateTime().CompareTo(condition.checkin.ConvertToDateTime()) == 0).Select(i => i);
}
}
if (!string.IsNullOrEmpty(condition.checkout))
{
if (condition.isDateRange)
{
result = result.Where(x => x.endDate.ConvertToDateTime().CompareTo(condition.checkout.ConvertToDateTime()) <= 0).Select(x => x);
}
else {
result = result.Where(x => x.endDate.ConvertToDateTime().CompareTo(condition.checkout.ConvertToDateTime()) == 0).Select(x => x);
}
}
result = result.Take(condition.itemsCount);
}
catch (Exception ex)
{
string message = ex.Message;
}
return result.ToList();
}
示例6: FromHsb
/// <summary>
/// Converts from HSB.
/// </summary>
public static Color FromHsb(IEnumerable<byte> source)
{
// http://ja.wikipedia.org/wiki/HSV%E8%89%B2%E7%A9%BA%E9%96%93
var h = Utility.ToUInt16(source.Take(2)) / 182.04;
var s = Utility.ToUInt16(source.Skip(2).Take(2)) / 655.35;
var b = Utility.ToUInt16(source.Skip(4).Take(2)) / 655.35;
// Convert to RGB
var h_i = (int)(Math.Floor(h / 60) % 6);
var f = (h / 60) - h_i;
var p = (int)(b * (1 - s));
var q = (int)(b * (1 - f * s));
var t = (int)(b * (1 - (1 - f) * s));
switch (h_i)
{
case 0:
return Color.FromArgb((int)b, t, p);
case 1:
return Color.FromArgb(q, (int)b, p);
case 2:
return Color.FromArgb(p, (int)b, t);
case 3:
return Color.FromArgb(p, q, (int)b);
case 4:
return Color.FromArgb(t, p, (int)b);
case 5:
return Color.FromArgb((int)b, p, q);
default:
throw new Exception();
}
}
示例7: PickNextTargets
public override IEnumerable<IUnit> PickNextTargets(IEnumerable<IUnit> candidateTargets)
{
if (base.Unit.HealthPoints <= 150)
return candidateTargets.Take(1);
else
return candidateTargets;
}
示例8: MapValuesImpl
private static IEnumerable<Tuple<SpecificationProperty, Maybe<Error>>> MapValuesImpl(
IEnumerable<SpecificationProperty> specProps,
IEnumerable<string> values,
Func<IEnumerable<string>, System.Type, bool, Maybe<object>> converter)
{
if (specProps.Empty() || values.Empty())
{
yield break;
}
var pt = specProps.First();
var taken = values.Take(pt.Specification.GetMaxValueCount().Return(n => n, values.Count()));
if (taken.Empty())
{
yield break;
}
yield return
converter(taken, pt.Property.PropertyType, pt.Specification.ConversionType.IsScalar())
.Return(
converted => Tuple.Create(pt.WithValue(Maybe.Just(converted)), Maybe.Nothing<Error>()),
Tuple.Create<SpecificationProperty, Maybe<Error>>(
pt, Maybe.Just<Error>(new BadFormatConversionError(NameInfo.EmptyName))));
foreach (var value in MapValuesImpl(specProps.Skip(1), values.Skip(taken.Count()), converter))
{
yield return value;
}
}
示例9: PathBuild
public override void PathBuild()
{
_links = CategoryWithChild(CategoryId);
CurrentCatalog(_links.First());
//skip the last element so he is our link
CategoryTree(_links.Take(_links.Count() - 1));
}
示例10: MergeResults
private static IEnumerable<Movie> MergeResults(IEnumerable<Movie> netflixResults, IEnumerable<Movie> rottenTomatoesResults)
{
var movies = (from nf in netflixResults
from rt in rottenTomatoesResults
where nf.Title.ToUpper() == rt.Title.ToUpper()
select new Movie
{
Title = nf.Title,
Availability = nf.Availability.Union(rt.Availability).ToList(),
Cast = rt.Cast,
Key = new MovieKey { NetflixId = nf.ProviderMovieId, RottenTomatoesId = rt.ProviderMovieId },
MPAARating = rt.MPAARating,
ProviderMovieId = "MovieMon",
Source = "MovieMon",
RelatedClips = rt.RelatedClips,
Reviews = rt.Reviews,
RunTime = nf.RunTime,
Summary = nf.Summary,
Rating = rt.Rating,
RelatedImages = nf.RelatedImages
}
).ToList();
var netflixMax = GetMax(netflixResults.Count());
var rtMax = GetMax(rottenTomatoesResults.Count());
var mergedMax = GetMax(movies.Count);
Logger.InfoFormat("Merging additional results: added {0} from netflix and {1} from rotten tomatoes", netflixMax, rtMax);
movies = movies.Take(mergedMax).ToList();
var merged = movies.Union(netflixResults.Take(netflixMax)).ToList();
merged = merged.Union(rottenTomatoesResults.Take(rtMax)).ToList();
var filtered = merged.Distinct(new MovieComparer()).ToList();
return filtered;
}
示例11: Combine
public void Combine(World world, IEnumerable<Actor> newSelection, bool isCombine, bool isClick)
{
if (isClick)
{
var adjNewSelection = newSelection.Take(1); /* TODO: select BEST, not FIRST */
if (isCombine)
actors.SymmetricExceptWith(adjNewSelection);
else
{
actors.Clear();
actors.UnionWith(adjNewSelection);
}
}
else
{
if (isCombine)
actors.UnionWith(newSelection);
else
{
actors.Clear();
actors.UnionWith(newSelection);
}
}
var voicedActor = actors.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.IsInWorld && a.HasTrait<IVoiced>());
if (voicedActor != null)
voicedActor.PlayVoice("Select");
foreach (var a in newSelection)
foreach (var sel in a.TraitsImplementing<INotifySelected>())
sel.Selected(a);
foreach (var ns in world.WorldActor.TraitsImplementing<INotifySelection>())
ns.SelectionChanged();
}
示例12: IsPartialOrMultipleRangeRequests
/// <summary> Determines if the set of specified RangeRequests represents a partial range or multiple range requests. </summary>
/// <remarks> ebrown, 2/14/2011. </remarks>
/// <exception cref="ArgumentNullException"> Thrown when rangeRequests are null. </exception>
/// <param name="rangeRequests"> The set of range requests (typically returned by TryParseRangeRequests). </param>
/// <param name="fileLength"> Total length of the file to which the requests apply. </param>
/// <returns> true if a set of range requests or the single range request is for a partial range, false if not. </returns>
public static bool IsPartialOrMultipleRangeRequests(IEnumerable<RangeRequest> rangeRequests, long fileLength)
{
if (null == rangeRequests) { throw new ArgumentNullException("rangeRequests"); }
var first = rangeRequests.FirstOrDefault();
return ((rangeRequests.Take(2).Count() > 1) || (0 != first.Start) || (fileLength != (first.End + 1)));
}
示例13: Load
/// <summary>
/// Loads the specified collection into the recent file list. Use this method when you need to initialize the RecentFileList
/// manually. This can be useful when you are using an own persistence implementation.
/// </summary>
/// <remarks>Recent file items that exist before the Load method is called are removed.</remarks>
/// <param name="recentFiles">The recent files.</param>
/// <exception cref="ArgumentNullException">The argument recentFiles must not be null.</exception>
public void Load(IEnumerable<RecentFile> recentFiles)
{
if (recentFiles == null) { throw new ArgumentNullException(nameof(recentFiles)); }
Clear();
AddRange(recentFiles.Take(maxFilesNumber));
}
示例14: 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;
}
示例15: Reduce
public IWordState Reduce(IEnumerable<IWordState> set, int len)
{
if (len == 0)
return new Chunk("");
if (len == 1)
return set.First();
else
{
int pivot = len / 2;
//var i1 = set.Take(pivot).ToList();
//var i2 = set.Skip(pivot).ToList();
//var t1 = new Task<IWordState>(() => Reduce(i1, pivot));
//var t2 = new Task<IWordState>(() => Reduce(i2, pivot + len % 2));
var firstHalf = Reduce(set.Take(pivot), pivot);
var secondHalf = Reduce(set.Skip(pivot), pivot + len % 2);
IWordState result = firstHalf.Combine(secondHalf);
return result;
}
}