i am working with list and my list has 14 record.
List<Product> oProduct = new List<Product>
{
new Product("../images/1.jpg", "Sample Data.1"),
new Product("../images/2.jpg", "Sample Data.2"),
new Product("../images/3.jpg", "Sample Data.3"),
new Product("../images/4.jpg", "Sample Data.4"),
new Product("../images/5.jpg", "Sample Data.5"),
new Product("../images/6.jpg", "Sample Data.6"),
new Product("../images/7.jpg", "Sample Data.7"),
new Product("../images/8.jpg", "Sample Data.8"),
new Product("../images/9.jpg", "Sample Data.9"),
new Product("../images/10.jpg", "Sample Data.10"),
new Product("../images/11.jpg", "Sample Data.11"),
new Product("../images/12.jpg", "Sample Data.12"),
new Product("../images/13.jpg", "Sample Data.13"),
new Product("../images/14.jpg", "Sample Data.14"),
};
when i use the below line for getrange then i am getting index out of bound error.
List<Product> xProduct = oProduct.GetRange(10, 13);
but my list has 14 element then why i can not extract data from 10th position to 14th position….please guide thanks.
The second parameter to
GetRangeneeds to be the count of elements to get, so change it to4(I think that’s what you want).Also, the first parameter is the zero-based index, so you want
GetRange(9, 4)to get images 10 through 13.