[英]Get Top(N-1) records from a List
I am selecting top 3 records from the Database. 我正在从数据库中选择前3条记录。 I want to display last 2 records except first record .How can we do this with C#. 我想显示除第一条记录外的最后2条记录。如何使用C#做到这一点。 i am using asp.net 2.0 ,so cannot use linq . 我正在使用asp.net 2.0,所以不能使用linq。
Won't it be: 不会是:
List<string> list = new List<string>();
for (int i = 1; i < 3; i++)
{
string s = list[i];
}
And if you are sure that it would always be the 2nd and 3rd items only, you can directly refer to them through the index value like: list[1]
and list[2]
而且,如果您确定它始终仅是第二项和第三项,则可以通过诸如list[1]
和list[2]
的索引值直接引用它们。
Why can't you just index into the list. 您为什么不能只索引列表。 Assuming you have only 3 items in the list: 假设列表中只有3个项目:
var item2 = list[1];
var item3 = list[2];
this will give you items 2 and 3. Unless if I misunderstood the question... 这将给您项目2和3。除非我误解了这个问题,否则...
for (int i = 1; i < 3; i++)
{
DisplayData(dataStructure[i]);
}
Sorry I didnt see the "so cannot use linq " part 抱歉,我没有看到“因此无法使用linq”部分
Add them to a List and use linq Skip 将它们添加到列表并使用linq Skip
Something similar to 类似于
var allButFirst1 = waOrders.Skip(1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.