JonnyJon44
JonnyJon44

Reputation: 69

Limit items List c#

How to do that from List ids in which 10 items in List cids, came in turn on 2 items?

internal List<items> test(List<long> ids)
{
    //ids = 10 items  
    List<long> cids = new List<long>(); // max 2 items in List<long> ids 

    var result= classA.GetValue(cids); //max cids items 2
    return result;
}

Upvotes: 1

Views: 6451

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460098

Is it really so simply? Use Take:

 internal List<items> test(List<long> ids)
 {
     return classA.GetValue(ids.Take(2).ToList()).Take(2).ToList();
 }

I dont know why you need to take 2 from the ids and pass these to GetValue as mentioned.

Upvotes: 5

Alex Paven
Alex Paven

Reputation: 5549

Using Linq,

var cids = ids.Take(2).ToList();

That's probably the simplest. Not much more to add... unless I gravely misunderstood the question.

Upvotes: 2

Related Questions