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


C# System.Collections.Generic.Take方法代码示例

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


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

示例1: IntervalTimePerTimeValuesAttribute

        static IntervalTimePerTimeValuesAttribute()
        {
            var values = new List<IQuantity>();

            var times = new[]
            {
                //TODO: ... however, us, ms, s, min, hr, are not unreasonable to expect ...
                T.Microsecond,
                T.Millisecond,
                T.Second,
                T.Minute,
                T.Hour,
                ////TODO: we do not care about Days or Weeks for purposes of these tests...
                //T.Day,
                //T.Week,
            };

            // TODO: TBD: Avoid scaling too absurdly: may want to be more selective than this...
            var length = times.Length - 2;

            // TODO: TBD: Could also vary the value itself, but this will do for starters...
            const double value = 1e2;

            var first = times.Take(length).ToArray();
            var second = times.Reverse().Take(length).ToArray();

            values.AddRange(from x in first from y in second select new Quantity(value, x, y.Invert()));
            values.AddRange(from y in first from x in second select new Quantity(value, x, y.Invert()));

            Values = values.OfType<object>().ToArray();
        }
开发者ID:mwpowellhtx,项目名称:clockworks,代码行数:31,代码来源:IntervalTimePerTimeValuesAttribute.cs

示例2: EqualityBasedOnNamesAndCount

 public void EqualityBasedOnNamesAndCount()
 {
     string[] names = new[] {"foo", "bar", "baz", "quux", "quuux"};
     for (int i = 0; i <= names.Length; ++i)
     {
         for (int j = 0; j != 3; ++j)
         {
             for (int x = 0; x <= names.Length; ++x)
             {
                 for (int y = 0; y != 3; ++y)
                 {
                     var info0 = new CallInfo(i + j, names.Take(i));
                     var info1 = new CallInfo(x + y, names.Take(x));
                     Assert.Equal(i == x & j == y, info0.Equals(info1));
                 }
             }
         }
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:19,代码来源:CallInfoTests.cs

示例3: HashCodeBasedOnEquality

 public void HashCodeBasedOnEquality()
 {
     string[] names = new[] {"foo", "bar", "baz", "quux", "quuux"};
     for (int i = 0; i <= names.Length; ++i)
     {
         for (int j = 0; j != 3; ++j)
         {
             for (int x = 0; x <= names.Length; ++x)
             {
                 for (int y = 0; y != 3; ++y)
                 {
                     var info0 = new CallInfo(i + j, names.Take(i));
                     var info1 = new CallInfo(x + y, names.Take(x));
                     if (info0.Equals(info1))
                     {
                         Assert.Equal(info0.GetHashCode(), info1.GetHashCode());
                     }
                     else
                     {
                         // Failure at this point is not definitely a bug,
                         // but should be considered a concern unless it can be
                         // convincingly ruled a fluke.
                         Assert.NotEqual(info0.GetHashCode(), info1.GetHashCode());
                     }
                 }
             }
         }
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:29,代码来源:CallInfoTests.cs

示例4: Get


//.........这里部分代码省略.........
                {
                    route = new []{ "projects", project1, "features", feature1, "estimates", estimate1 },
                    payload = new Payload
                    {
                        values = new
                        {
                            Player = new [] { "projects", project1, "players", player1 },
                            Card = StoryPoints.Points008
                        }.ToDictionary()
                    }
                },
                new ModelEvent
                {
                    route = new []{ "projects", project1, "features", feature1, "estimates", estimate2 },
                    payload = new Payload
                    {
                        values = new
                        {
                            Player = new [] { "projects", project1, "players", player2 },
                            Card = StoryPoints.Points005
                        }.ToDictionary()
                    }
                },
                new ModelEvent
                {
                    route = new []{ "projects", project1, "features", feature1, "estimates", estimate3 },
                    payload = new Payload
                    {
                        values = new
                        {
                            Player = new [] { "projects", project1, "players", player3 },
                            Card = StoryPoints.Points003
                        }.ToDictionary()
                    }
                },
                new ModelEvent
                {
                    route = new []{ "projects", project1, "features", feature1, "estimates", estimate4 },
                    payload = new Payload
                    {
                        values = new
                        {
                            Player = new [] { "projects", project1, "players", player3 },
                            Card = StoryPoints.Break
                        }.ToDictionary()
                    }
                },
                new ModelEvent
                {
                    route = new []{ "projects", project1, "features", feature1, "estimates", estimate5 },
                    payload = new Payload
                    {
                        values = new
                        {
                            Player = new [] { "projects", project1, "players", player4 },
                            Card = StoryPoints.DontKnow
                        }.ToDictionary()
                    }
                },
                new ModelEvent
                {
                    route = new []{ "projects", project1, "features", feature1, "estimates", estimate2 },
                    payload = new Payload
                    {
                        values = new
                        {
                            Player = new [] { "projects", project1, "players", player2 },
                            Card =  StoryPoints.Break,
                        }.ToDictionary()
                    }
                },
                new ModelEvent
                {
                    route = new []{ "projects", project1, "features", feature1, "estimates" },
                    payload = new Payload
                    {
                        delete = new []{ estimate2 }
                    }
                },
                new ModelEvent
                {
                    route = new []{ "projects", project1, "features", feature1, "estimates", estimate2 },
                    payload = new Payload
                    {
                        values = new
                        {
                            Player = new [] { "projects", project1, "players", player2 },
                            Card =  StoryPoints.Points013,
                        }.ToDictionary()
                    }
                },
            };

            if (take == null)
            {
                return events;
            }

            return events.Take(take.Value);
        }
开发者ID:jimtaylor1974,项目名称:planning-poker,代码行数:101,代码来源:ExampleEvents.cs

示例5: WhenInstancesRemoved_ShouldOnlyDistributeAcrossRemainingInstances

        public void WhenInstancesRemoved_ShouldOnlyDistributeAcrossRemainingInstances()
        {
            var strategy = new SingleInstanceRoundRobinDistributionStrategy("endpointA", DistributionStrategyScope.Send);

            var instances = new []
            {
                "1",
                "2",
                "3"
            };

            var result = new List<string>();
            result.Add(strategy.SelectReceiver(instances));
            result.Add(strategy.SelectReceiver(instances));
            instances = instances.Take(2).ToArray(); // remove last instance.
            result.Add(strategy.SelectReceiver(instances));

            Assert.That(result.Count, Is.EqualTo(3));
            Assert.That(result, Has.Exactly(2).EqualTo(instances[0]));
            Assert.That(result, Has.Exactly(1).EqualTo(instances[1]));
        }
开发者ID:Particular,项目名称:NServiceBus,代码行数:21,代码来源:SingleInstanceRoundRobinDistributionStrategyTests.cs

示例6: should_take_first_n_elements_using_take

        public void should_take_first_n_elements_using_take()
        {
            var sequence = new[] {1, 2, 3, 4, 5};

            IEnumerable<int> filteredElements = sequence.Take(3);

            // please update variable value to fix the test.
            IEnumerable<int> expectedResult = new[] {1, 2, 3, 4, 5};

            Assert.Equal(expectedResult, filteredElements);
        }
开发者ID:chenbojian,项目名称:01_NewbieVillage,代码行数:11,代码来源:24_LinqBasics.cs

示例7: Must_result_in_non_zero

			public void Must_result_in_non_zero()
			{
				const string sql = "sql";
				IEnumerable<DbParameter> parameters = new[]
					{
						new SqlParameter("@Test1", 0),
						new SqlParameter("@Test2", "Test"),
						new SqlParameter("@Test3", 1.45m)
					};

				var cacheKey1 = new CacheKey(sql, parameters.Take(1).Skip(1).Take(1));
				var cacheKey2 = new CacheKey(sql, parameters);
				int result = Comparer<CacheKey>.Default.Compare(cacheKey1, cacheKey2);

				Assert.That(result, Is.EqualTo(-1));
			}
开发者ID:nathan-alden,项目名称:junior-persist,代码行数:16,代码来源:CacheKeyTester.cs


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