本文整理汇总了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();
}
示例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));
}
}
}
}
}
示例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());
}
}
}
}
}
}
示例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);
}
示例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]));
}
示例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);
}
示例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));
}