本文整理汇总了C#中System.Take方法的典型用法代码示例。如果您正苦于以下问题:C# System.Take方法的具体用法?C# System.Take怎么用?C# System.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.Take方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVedlegg
internal static IEnumerable<Dokument> GetVedlegg(int antall = 5)
{
var vedleggTxt0 = new Dokument("Vedlegg", ResourceUtility.ReadAllBytes(true, "vedlegg", "Vedlegg.txt"), "text/plain");
var vedleggDocx = new Dokument("Vedleggsgris", ResourceUtility.ReadAllBytes(true, "vedlegg", "VedleggsGris.docx"), "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
var vedleggPdf = new Dokument("Vedleggshjelm", ResourceUtility.ReadAllBytes(true, "vedlegg", "VedleggsHjelm.pdf"), "application/pdf");
var vedleggTxt1 = new Dokument("Vedlegg", ResourceUtility.ReadAllBytes(true, "vedlegg", "Vedlegg.txt"), "text/plain");
var vedleggTxt2 = new Dokument("Vedlegg", ResourceUtility.ReadAllBytes(true, "vedlegg", "Vedlegg.txt"), "text/plain");
var vedlegg = new[] {vedleggTxt0, vedleggDocx, vedleggPdf, vedleggTxt1, vedleggTxt2};
if (antall <= 5)
{
return vedlegg.Take(antall);
}
else
{
var vedleggbatch = new List<Dokument>();
for (var i = 0; i < antall; i++)
{
var element = vedlegg.ElementAt(i % vedlegg.Length);
vedleggbatch.Add(new Dokument(element.Tittel, element.Bytes, element.MimeType, "NO", $"{i}-{element.Filnavn}"));
}
return vedleggbatch;
}
}
示例2: E_SlicingArrays
public void E_SlicingArrays()
{
var array = new[] { "peanut", "butter", "and", "jelly" };
Assert.AreEqual(new string[] { (string)FILL_ME_IN, (string)FILL_ME_IN }, array.Take(2).ToArray());
Assert.AreEqual(new string[] { (string)FILL_ME_IN, (string)FILL_ME_IN }, array.Skip(1).Take(2).ToArray());
}
示例3: ActionAlternatesFactory
public ActionAlternatesFactory(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
_actionAlternates = new Lazy<List<string>>(() =>
{
var httpContext = _httpContextAccessor.Current();
if (httpContext == null)
{
return null;
}
var request = _httpContextAccessor.Current().Request;
var actionSegments = new[]
{
request.RequestContext.RouteData.GetRequiredString("area").Replace("-", "__").Replace(".", "_"),
request.RequestContext.RouteData.GetRequiredString("controller").Replace("-", "__").Replace(".", "_"),
request.RequestContext.RouteData.GetRequiredString("action").Replace("-", "__").Replace(".", "_")
};
return Enumerable.Range(1, actionSegments.Count()).Select(range => String.Join("__", actionSegments.Take(range))).ToList();
});
}
示例4: EndExclusive
public void EndExclusive()
{
var spans = new[]
{
new ILSpan(0u, uint.MaxValue),
new ILSpan(1, 9),
new ILSpan(2, 8),
new ILSpan(1, 3),
new ILSpan(7, 9),
};
Assert.Equal(new ILSpan(0u, uint.MaxValue), MethodContextReuseConstraints.CalculateReuseSpan(5, ILSpan.MaxValue, spans.Take(1)));
Assert.Equal(new ILSpan(1, 9), MethodContextReuseConstraints.CalculateReuseSpan(5, ILSpan.MaxValue, spans.Take(2)));
Assert.Equal(new ILSpan(2, 8), MethodContextReuseConstraints.CalculateReuseSpan(5, ILSpan.MaxValue, spans.Take(3)));
Assert.Equal(new ILSpan(3, 8), MethodContextReuseConstraints.CalculateReuseSpan(5, ILSpan.MaxValue, spans.Take(4)));
Assert.Equal(new ILSpan(3, 7), MethodContextReuseConstraints.CalculateReuseSpan(5, ILSpan.MaxValue, spans.Take(5)));
}
示例5: Take_TakesItems
public void Take_TakesItems()
{
var queryable = new[] { "1", "3", "6", "2", "8" }.AsQueryable();
var source = new Source<string>(queryable);
var expected = queryable.Take(3).ToList();
var actual = source.Take(3).ToList();
CollectionAssert.AreEqual(expected, actual);
}
示例6: ShareWorksForArray
public void ShareWorksForArray()
{
var result = new List<int>();
var enm = new[] { 1, 2, 3, 4, 5 }.Share();
enm.Take(3).ForEach(i => result.Add(i));
result.Add(-1);
enm.ForEach(i => result.Add(i));
Assert.AreEqual(result, new[] { 1, 2, 3, -1, 4, 5 });
}
示例7: MaxBy
public void MaxBy()
{
var data = new[] { "A", "B", "C", "DZ" };
Assert.Throws<NullReferenceException> (() => ((IEnumerable<string>)null).MaxBy(x => x.Length));
Assert.Throws<NullReferenceException> (() => data.MaxBy<string, int>(null));
Assert.Throws<InvalidOperationException>(() => new string[0].MaxBy(x => x.Length));
Assert.Equal("DZ", data.MaxBy(x => x.Length));
Assert.Equal("A", data.Take(3).MaxBy(x => x.Length));
}
示例8: TestMultiplePartitionsShorterThanSequence
public void TestMultiplePartitionsShorterThanSequence()
{
const int count = 100;
var parSizes = new[] { 10, 20, 30, 40 };
var sequence = Enumerable.Range(1, count);
var result = sequence.Partition(parSizes);
var index = 0;
foreach (var resultSequence in result)
{
Assert.AreEqual(parSizes[index], resultSequence.Count());
Assert.IsTrue(resultSequence.SequenceEqual(sequence.Skip(parSizes.Take(index).Sum())
.Take(parSizes[index])));
++index;
}
}
示例9: Test_Lazy_Pumping
public void Test_Lazy_Pumping()
{
var log = new List<string>();
var results = new XmlPipeline()
.Source(new[] { new DummyXmlSource("-1"), new DummyXmlSource("-2"), new DummyXmlSource("-3") })
.Pipe(new DummyXmlTransform())
.Destination(new DummyXmlDestination(name => log.Add(name)))
.Pump();
Assert.That(log.ToArray(), Is.EqualTo(new string[0]));
var expected = new[] { "dummy-source-1", "dummy-source-2", "dummy-source-3" };
var i = 1;
foreach (var result in results)
{
Assert.That(log.ToArray(), Is.EqualTo(expected.Take(i++)));
}
}
示例10: Invoke
private static IEnumerable<KeyValuePair<ExpressionType, Expression>> Invoke()
{
var p = Expression.Parameter(typeof(int));
var i = Expression.Parameter(typeof(Action));
var d = Expression.Parameter(typeof(Action));
var cs = new[] { i, i, i, d, i, d, d, i };
for (var j = 1; j < cs.Length; j++)
{
yield return new KeyValuePair<ExpressionType, Expression>(ExpressionType.Invoke,
Expression.Block(
new[] { p, i, d },
Expression.Assign(i, Expression.Lambda<Action>(Expression.PostIncrementAssign(p))),
Expression.Assign(d, Expression.Lambda<Action>(Expression.PostDecrementAssign(p))),
Expression.Block(cs.Take(j).Select(e => Expression.Invoke(e))),
p
)
);
}
}
示例11: NestedDeepTranslationTest
public void NestedDeepTranslationTest()
{
EnableDebugViewer();
List<Node> nodes =
new[]
{
new Node(CurveFactory.CreateRectangle(30, 20, new Point())),
new Node(CurveFactory.CreateRectangle(30, 20, new Point(100, 0))),
new Node(CurveFactory.CreateRectangle(30, 20, new Point(200, 0)))
}
.ToList();
var graph = new GeometryGraph();
nodes.ForEach(graph.Nodes.Add);
nodes.Add(CreateCluster(nodes.Take(2), 10));
Assert.AreEqual(nodes[3].BoundingBox.Width, 150, "Inner Cluster has incorrect width");
Assert.AreEqual(nodes[3].BoundingBox.Height, 40, "Inner Cluster has incorrect height");
nodes.Add(CreateCluster(new[] { nodes[3], nodes[2] }, 10));
graph.RootCluster = new Cluster(new Node[] { }, new[] { (Cluster)nodes[4] });
List<Edge> edges = new[]
{
new Edge(nodes[0], nodes[1]), new Edge(nodes[0], nodes[2]), new Edge(nodes[2], nodes[1]), new Edge(nodes[3], nodes[2]),
new Edge(nodes[2], nodes[3])
}
.ToList();
edges.ForEach(graph.Edges.Add);
RouteEdges(graph, 10);
var bounds = (from v in nodes select v.BoundingBox).Concat(from e in edges select e.BoundingBox).ToList();
var delta = new Point(10, 20);
((Cluster)nodes[4]).DeepTranslation(delta, true);
ShowGraphInDebugViewer(graph);
IEnumerable<GeometryObject> geometryObjects = (from v in nodes select (GeometryObject)v).Concat(from e in edges select (GeometryObject)e);
foreach (var b in geometryObjects.Zip(bounds, (g, b) => new { G = g, Original = b, Target = g.BoundingBox }))
{
Assert.IsTrue(ApproximateComparer.Close(Rectangle.Translate(b.Original, delta), b.Target), "object was not translated: " + b.G);
}
}
示例12: Main
public static void Main(string[] args)
{
var asm = Assembly.GetExecutingAssembly();
var stream = asm.GetManifestResourceStream("Example.vector.txt");
var text = new StreamReader(stream).ReadToEnd();
var template = Template.Create(text);
var comps = new[] { "x", "y", "z", "w" };
var operators = new[] { "+", "-", "*", "/" };
for(int i = 0; i < 4; ++i) {
var dim = i+1;
var def = new VectorDef() {
dim = dim,
components = comps.Take(dim).ToArray(),
operators = operators,
baseType = "float",
};
Console.WriteLine(template.Render(def));
}
}
示例13: GetSharedMedia
public Payload GetSharedMedia(string id, bool includeChildren, int startIndex, int requestCount)
{
_hierarchy = _hierarchy ?? CreateHierarchy();
var node = _hierarchy.GetNode(id);
IEnumerable<AbstractSharedMediaInfo> nodes = new []{node.ToMedia()};
if (includeChildren)
{
nodes = _hierarchy.GetChildren(node).Select(n => n.ToMedia())
.Skip(startIndex);
if (requestCount != 0)
{
nodes = nodes.Take(requestCount);
}
}
var list = nodes.ToArray();
ApplySortIndexes(list);
return new Payload(node.Id, node.ParentId, node.Title, 0, list, node.IsContainer);
}
示例14: TestContainsNonCollection
public void TestContainsNonCollection() {
Func<bool> f = () => {
var a = new[] { 1, 2, 3 };
return a.Skip(1).Contains(2) && !a.Take(1).Contains(2);
};
this.Test(f, true);
}
示例15: TestSingleOrDefaultNonCollectionTooMany
public void TestSingleOrDefaultNonCollectionTooMany() {
Func<int> f = () => {
var a = new[] { 1, 2 };
try {
return a.Take(2).SingleOrDefault();
} catch {
return -1;
}
};
this.Test(f, -1);
}