当前位置: 首页>>代码示例>>C#>>正文


C# IEnumerable.Take方法代码示例

本文整理汇总了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);
 }
开发者ID:Epitomy,项目名称:CMS,代码行数:12,代码来源:Theme.cs

示例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; }
     }
 }
开发者ID:UIKit0,项目名称:StrongNameResigner,代码行数:31,代码来源:BinaryUtility.cs

示例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;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:26,代码来源:Program.cs

示例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;
        }
开发者ID:494760542,项目名称:Square,代码行数:27,代码来源:SplitListHelper.cs

示例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();
        }
开发者ID:ZengYuming,项目名称:TNS,代码行数:35,代码来源:RealtimeReviewService.cs

示例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();
            }
        }
开发者ID:mayth,项目名称:AcoDraw,代码行数:34,代码来源:ColorConverter.cs

示例7: PickNextTargets

 public override IEnumerable<IUnit> PickNextTargets(IEnumerable<IUnit> candidateTargets)
 {
     if (base.Unit.HealthPoints <= 150)
         return candidateTargets.Take(1);
     else
         return candidateTargets;
 }
开发者ID:LyuboslavLyubenov,项目名称:OOP,代码行数:7,代码来源:IceGigantCombatHandler.cs

示例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;
            }
        }
开发者ID:BiYiTuan,项目名称:commandline,代码行数:28,代码来源:ValueMapper.cs

示例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));
 }
开发者ID:vitek0585,项目名称:FashionStore,代码行数:7,代码来源:CategoryBCBuilder.cs

示例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;
        }
开发者ID:SpitfireTS,项目名称:MovieMon,代码行数:35,代码来源:SearchHelper.cs

示例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();
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:34,代码来源:Selection.cs

示例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)));
        }
开发者ID:Iristyle,项目名称:Authentic,代码行数:13,代码来源:RangeRequestHelpers.cs

示例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));
        }
开发者ID:jbe2277,项目名称:waf,代码行数:14,代码来源:RecentFileList.cs

示例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;
        }
开发者ID:conradakunga,项目名称:QuantTrading,代码行数:39,代码来源:EMA.cs

示例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;
            }
        }
开发者ID:kumar-abhishek,项目名称:Algorithmic-Alley,代码行数:25,代码来源:DivideAndConquerSplitter.cs


注:本文中的IEnumerable.Take方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。