score:0
Accepted answer
class program
{
static void main(string[] args)
{
var populatedlist = new list<string>
{
"one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten"
};
var fillthislist = new list<string>();
int itr = 1;
int keep = 3;
int skip = 7;
foreach (var item in populatedlist)
{
if (itr == skip)
{
// reset the iterator
itr = 1;
continue;
}
if (itr <= keep)
{
fillthislist.add(item);
}
itr++;
}
}
}
score:0
public static list<t> paginatewithoffset<t>(list<t> list, int offset, int pagesize)
{
list<t> templist = new list<t>();
if (offset < 0 || pagesize < 0 || offset >= list.count || list.count == 0)
{
return list;
}
else
{
int endpage = offset + pagesize;
int startpage = offset;
if ((startpage < list.count && endpage > list.count) || (pagesize == 0))
{
endpage = list.count;
}
for (int i = startpage; i < endpage; i++)
{
templist.add(list[i]);
}
return templist;
}
}
score:1
var coll = new observablecollection<string>()
{
"test1","test2","test3","test4","test5","test6","test7","test8","test9","test10","test11","tes12t","test13","test14","test15"
};
var res = coll.takesomeignoresome(3,4); // returns 1,2,3,8,9,10,15
Source: stackoverflow.com
Related Query
- Loop through observable collection to create a new observable collection
- How to loop through var object collection in C#?
- Using LINQ to loop through inner class properties in outer class collection
- Is there an easy way for me to iterate through a collection and create a report?
- Using LINQ to loop through inner class properties in outer class collection and group by outer class properties
- LINQ Create new Xdocument by looping through existing XML file
- C# create new collection from two collections
- c# How can I create a collection of custom objects without going through each field
- Create XML tree from observable collection
- How can I create an observable collection from LINQ that was written to create an array?
- LINQ loop through a collection and append an increment to matching values
- MVC loop through array to find data of each location in a table and create a seperate table for each
- Join 2 collection list together from 2 data sources find the matches and loop through the results
- Linq - Create new object which contains a collection
- How do I loop through a collection of LINQ to Entities collection?
- How do I quickly create a new collection of objects from a collection of larger objects?
- ToList()-- does it create a new list?
- Apply function to all elements of collection through LINQ
- Favorite way to create an new IEnumerable<T> sequence from a single value?
- System.LINQ.Dynamic: Select(" new (...)") into a List<T> (or any other enumerable collection of <T>)
- Sorting an observable collection with linq
- Get new indices of items in a collection after sorting using LINQ
- Dynamically add new lambda expressions to create a filter
- Enumerating through list of expressions to filter collection
- Create a new anonymous type list to union onto existing anonymous type list
- ASP.Net / C#, Loop through certain controls on a page?
- LINQ query to create a collection of objects combined from a collection of strings
- Can I use LINQ to create a new list of objects from an existing list
- System.LINQ.Dynamic: Select(“ new classname (…)”) into a List<T> (or any other enumerable collection of <T>)
- Loop Through LINQ Query Columns (Not rows)
More Query from same tag
- How to scaffold a SQL Server database with ASP.Net Entity Framework
- Using the generic type System.Collections.Generic.List<T> requires 1 type arguments
- Set of values in one or other list but not both
- Linq wont return List
- How do I get active rows in 1 to many relationship using Linq?
- LINQ Select statement with EF - object initializer reuse assignment
- how to filter from nested collections without ForEach?
- Best method for programmatically requesting db table columns using LINQ
- How to know if I Won the lottery In C#
- LINQ projection to presentation model
- C# String Splitting of a path to get every sub path
- Entity-framework / Linq: How to left join while grouping into custom select?
- LINQ with multiple selection and group by multiple selection
- Linq to Entities with two tables
- Reading a file line by line in C#
- Expression to create instance and set members not using MemberInit
- ASP.NET Core 3.1 / EF Core - Search table column by string name
- Expected Contextual keyword 'on'
- Sorting 2D data in a list
- Why is there no Linq method to return distinct values by a predicate?
- Nhibernate linq fetch in subclass
- LINQ Where clause misunderstanding
- Linq query taking too long to process results
- Linq Group By multiple properties in VB.Net
- SQL to LINQ - Multiple Group By Statements and a Join
- LINQ generating wrong SQL for empty string
- Which namespace to include to strongly type the property with DbEntityEntry.Property
- LINQ to SQL, Stored Procedures and the Methods Pane (more like Methods PAIN!)
- SQL Server version of Oracle's CONNECT BY in LINQ to show hierachy
- Custom ordering using LINQ