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


C# ICollection.Take方法代码示例

本文整理汇总了C#中ICollection.Take方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Take方法的具体用法?C# ICollection.Take怎么用?C# ICollection.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICollection的用法示例。


在下文中一共展示了ICollection.Take方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUpClass

        public static void SetUpClass(TestContext context)
        {
            var seq = new SequentialGenerator<int> { Direction = GeneratorDirection.Ascending };
            var gen = new RandomGenerator();

            data_users = Builder<User>
                .CreateListOfSize(10)
                .All()
                    .With(u => u.DisplayName = gen.Phrase(15))
                    .Build();

            data_channels = Builder<Channel>
                .CreateListOfSize(20)
                .All()
                    .With(m => m.Id = seq.Generate())
                    .And(x => x.Name = gen.Phrase(15))
                    .And(x => x.AuthorId = gen.Phrase(10))
                    .And(x => x.Author = data_users.First())
                    .And(x => x.Loops = gen.Boolean())
                    .And(x => x.DateCreated = gen.DateTime())
                    .And(x => x.DateUpdated = x.DateCreated + new TimeSpan(3, 0, 0))
                .Random(10)
                    .With(x => x.DateDeactivated = x.DateUpdated + new TimeSpan(3, 0, 0))
                .Build();

            data_musics = Builder<Music>
                .CreateListOfSize(50)
                .All()
                    .With(m => m.Id = seq.Generate())
                    .And(m => m.LengthInMilliseconds = gen.Int())
                    .And(m => m.SizeInBytes = gen.Int())
                    .And(m => m.DateCreated = gen.DateTime())
                    .And(m => m.DateUpdated = m.DateCreated + new TimeSpan(3, 0, 0))
                .Build();

            channels = new Mock<ChannelService>(null);
            musics = new Mock<MusicService>(null);

            channels
                .Setup(x => x.All())
                .ReturnsAsync(data_channels);

            channels
                .Setup(x => x.Paginate(0, 10))
                .ReturnsAsync(data_channels.Take(10).ToList());

            channels
                .Setup(x => x.ActiveChannels(0, 4))
                .ReturnsAsync(data_channels.Take(4).ToList());

            channels
                .Setup(c => c.Deactivate(It.IsAny<Channel>()))
                .ReturnsAsync(1);
        }
开发者ID:uheerme,项目名称:core,代码行数:54,代码来源:ChannelsControllerTest.cs

示例2: ListsFromGuidCollection

        protected static Lists ListsFromGuidCollection(ICollection<Guid> hashLists, int size, IStorage storage )
        {
            var lists = from listId in hashLists.Take(size)
                        select new ListApi(listId, storage.List.GetInfo(listId));

            return new Lists(lists.ToList());
        }
开发者ID:ismaelbelghiti,项目名称:Tigwi,代码行数:7,代码来源:ApiController.cs

示例3: AddAlternates

 private static void AddAlternates(ShapeMetadata metadata, ICollection<string> values)
 {
     for (var i = 0; i < values.Count; i++)
     {
         var alternate = EncodeAlternate($"{metadata.Type}__{String.Join("_", values.Take(i + 1))}");
         metadata.Alternates.Add(alternate);
     }
 }
开发者ID:IDeliverable,项目名称:IDeliverable.Bits,代码行数:8,代码来源:RouteValuesAlternatesProvider.cs

示例4: AccountsFromGuidCollection

        // Methods to build the lists to return
        protected static Accounts AccountsFromGuidCollection(ICollection<Guid> hashAccounts, int size, IStorage storage)
        {
            var accounts = from accountId in hashAccounts.Take(size)
                           let accountInfo = storage.Account.GetInfo(accountId)
                           select new Account(accountId, accountInfo.Name, accountInfo.Description);

            return new Accounts(accounts.ToList());
        }
开发者ID:ismaelbelghiti,项目名称:Tigwi,代码行数:9,代码来源:ApiController.cs

示例5: HandleDoubleWordSurnamePrefix

		private static void HandleDoubleWordSurnamePrefix(NameParts result, ICollection<string> parts)
		{
			if (!IsTwoPartSurnamePrefix(parts))
			{
				return;
			}

			result.Surname = String.Join(" ", parts.Skip(parts.Count - 2).Take(2)) + " " + result.Surname;
			result.MiddleName = parts.Count == 2 ? null : String.Join(" ", parts.Take(parts.Count - 2));
		}
开发者ID:maxshenfield,项目名称:NameParsing,代码行数:10,代码来源:StringExtensions.cs

示例6: GivenThat

        /// <summary>
        /// Setup the critic
        /// </summary>
        protected override void GivenThat()
        {
            base.GivenThat();

            this._movies = new List<IMovie>();

            for (var i = 0; i < 10; i++)
            {
                this._movies.Add(Mock<IMovie>());
            }

            foreach (var movie in _movies.Take(5))
            {
                var movie1 = movie;

                Dep<IMovieCritic>().Stub(c => c.IsViolent(movie1)).Return(true);
            }
        }
开发者ID:TheEvilDev,项目名称:mt_testing,代码行数:21,代码来源:When_media_library_lists_non_violent_movies.cs

示例7: SortAndCount

        public static int[] SortAndCount(ICollection<int> unsortedArray, out long inversionCount)
        {
            if (unsortedArray.Count <= 1)
            {
                inversionCount = 0;
                return unsortedArray.ToArray();
            }

            int length = unsortedArray.Count;
            int half = length/2;

            long leftInversionCount, rightInversionCount, splitInversionCount;
            var left = SortAndCount(unsortedArray.Take(half).ToArray(), out leftInversionCount);
            var right = SortAndCount(unsortedArray.Skip(half).Take(length - half).ToArray(), out rightInversionCount);
            var sortedArray = MergeAndCount(length, left, right, out splitInversionCount);
            inversionCount = leftInversionCount + rightInversionCount + splitInversionCount;

            return sortedArray;
        }
开发者ID:sejoker,项目名称:ProgrammingChallenges,代码行数:19,代码来源:MergeSort.cs

示例8: PrepareEncodingData

        private static byte[] PrepareEncodingData(SymmetricAlgorithm algorithm, Random randomProvider, ICollection<byte> data)
        {
            // ограничиваем размер пароля
            var dataLength = (byte)data.Count;
            var preparedBytes = new List<byte> { dataLength };
            preparedBytes.AddRange(data.Take(dataLength));

            // дополняем пароль произвольными символами до размера блока шифрования
            var blockSize = algorithm.BlockSize / 8;
            var additionalBytesCount = preparedBytes.Count % blockSize;
            if (additionalBytesCount > 0)
            {
                additionalBytesCount = blockSize - additionalBytesCount;
                var additionalBytes = new byte[additionalBytesCount];
                randomProvider.NextBytes(additionalBytes);
                preparedBytes.AddRange(additionalBytes);
            }

            return preparedBytes.ToArray();
        }
开发者ID:Markeli,项目名称:BeardlyTeam,代码行数:20,代码来源:SecurityProvider.cs

示例9: AddRange

        public void AddRange(ICollection<Nucleotide> items)
        {
            var nbc = (Count + items.Count + 3)/4;
            if (nbc > _data.Length)
                Array.Resize(ref _data, Math.Max(nbc, _data.Length*2));
            var byteId = Count/4;
            var packId = Count%4;
            var curByte = _data[byteId];
            int skipHeader;
            if (packId > 0)
            {

                var itemHeader = items.Take(4 - packId).ToArray();
                skipHeader = itemHeader.Length;
                for (int i = packId; i < 4 && i < itemHeader.Length+packId; i++)
                {
                    var shift = 2*i;
                    curByte = (byte) ((curByte & ~(0x03 << shift)) | ((int) itemHeader[i - packId] << shift));
                }
                _data[byteId] = curByte;
                Count += skipHeader;
                byteId++;
                packId = 0;
            }
            else
                skipHeader = 0;

            byte tmp = 0;
            foreach (var item in items.Skip(skipHeader))
            {
                var shift = 2*packId;
                tmp =  (byte)(tmp | ((int)item << shift));
                Count++;
                packId = (packId + 1)%4;
                if (packId == 0)
                    _data[byteId++] = tmp;
            }
            if (packId != 0)
                _data[byteId] = tmp;
        }
开发者ID:supcry,项目名称:MotifSeeker,代码行数:40,代码来源:Chromosome.cs

示例10: Sort

 public IEnumerable<String> Sort(
     ICollection<String> strings)
 {
     return strings
         .Skip(6)
         .Concat(strings.Skip(2).Take(6))
         .Concat(strings.Take(2));
 }
开发者ID:Roddoric,项目名称:Monkey.Robotics,代码行数:8,代码来源:TestPreprocessedFiles.cs

示例11: BoolArrayToString

 private static string BoolArrayToString(ICollection<bool> array)
 {
     var s = new StringBuilder(array.Count);
     foreach (var b in array.Take(10))
     {
         s.Append(b ? '1' : '0');
     }
     return s.ToString();
 }
开发者ID:JakeLardinois,项目名称:HelicopterControl,代码行数:9,代码来源:Program.cs

示例12: CountChangeIter

 private static int CountChangeIter(double x, ICollection<double> changes)
 {
     var n = changes.Count;
     if (n == 0)
     {
         return 0;
     }
     var minChange = changes.Last();
     if (System.Math.Abs(x - minChange) <= 1e-5)
     {
         return 1;
     }
     if (x < minChange)
     {
         return 0;
     }
     return CountChangeIter(x - minChange, changes) + CountChangeIter(x, changes.Take(n - 1).ToList());
 }
开发者ID:ccpromise,项目名称:Code-Log,代码行数:18,代码来源:PuzzleBefore.cs

示例13: HasMinSizeSegments

        /// <summary>
        /// Determines if the collection of StorageObjects meets the minimum size requirements for a static large object manifest.
        /// </summary>
        /// <param name="segments">A collection of StorageObjects.</param>
        /// <param name="minSegmentSize">The minimum size in bytes for segments.</param>
        /// <returns>A value indicating if the collection meets the minimum size criteria.</returns>
        internal bool HasMinSizeSegments(ICollection<StorageObject> segments, long minSegmentSize)
        {
            segments.AssertIsNotNull("segments", "Cannot ensure that a collection of segments meets minimum size criteria with a null segment collection.");
            var segmentsToCheck = new List<StorageObject>();
            if (segments.Count == 0)
            {
                //If the collection is empty it does not have any segments that are of the min size.
                return false;
            }

            if (segments.Count == 1)
            {
                //If the collection only has one element then it must meet the criteria (even though the spec says the last segment can be any size).
                segmentsToCheck.Add(segments.First());
            }
            else
            {
                //All segments except the last one must be large then the min size.
                segmentsToCheck.AddRange(segments.Take(segments.Count -1));
            }

            return segmentsToCheck.All(s => s.Length > minSegmentSize);
        }
开发者ID:jasonzhuyx,项目名称:openstack-sdk-dotnet,代码行数:29,代码来源:LargeStorageObjectCreator.cs

示例14: AddRange

        public void AddRange(ICollection<Nucleotide> items)
        {
            var nbc = (Count + items.Count + 3) / 4;
            if (nbc > _data.Length)
                Array.Resize(ref _data, Math.Max(nbc, _data.Length*2));

            var byteId = Count / 4;
            var packId = Count % 4;
            var curByte = _data[byteId];
            int skipHeader;
            if (packId > 0)
            {

                var itemHeader = items.Take(4 - packId).ToArray();
                skipHeader = itemHeader.Length;
                for (int i = packId; i < 4 && i < itemHeader.Length + packId; i++)
                {
                    var shift = 2 * i;
                    curByte = (byte)((curByte & ~(0x03 << shift)) | ((int)itemHeader[i - packId] << shift));
                }
                _data[byteId] = curByte;
                Count += skipHeader;
                byteId++;
                packId = 0;
            }
            else
                skipHeader = 0;

            byte tmp = 0;
            foreach (var item in items.Skip(skipHeader))
            {
                var shift = 2 * packId;
                tmp = (byte)(tmp | ((int)item << shift));
                Count++;
                packId = (packId + 1) % 4;
                if (packId == 0)
                    _data[byteId++] = tmp;
            }
            if (packId != 0)
                _data[byteId] = tmp;

            // допишем маску. 1 - есть, 0 - нет.
            var mbc = (Count + items.Count + 7) / 8;
            if (mbc > _mask.Length)
                Array.Resize(ref _mask, Math.Max(mbc, _mask.Length * 2));

            int pos = Count - items.Count;
            foreach (var item in items)
            {
                if (item != Nucleotide.Any)
                    _mask[pos/8] |= (byte)(1 << (pos%8));
                pos++;
            }
            _maskSizes = null;
        }
开发者ID:supcry,项目名称:MotifSeeker,代码行数:55,代码来源:Chromosome.cs

示例15: GetTop5Results

 private ICollection<IPlayer> GetTop5Results(ICollection<IPlayer> players)
 {
     return players.Take(5).ToList();
 }
开发者ID:RadoChervenkov,项目名称:Minesweeper,代码行数:4,代码来源:ScoreBoard.cs


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