I have a query in which I fill a List with the values of a column called Quantity, assuming that the values of the list are the following:
Position= P value= v
p v
[0] 41
[1] 42
[2] 43
[3] 44
[4] 45
[5] 46
[6] 47
[7] 9
[8] 10
[9] 11
[10] 12
And I have a variable value="45", and we see that in the list there is a value "45" and that its index is [4], so what I want now is to show the values of the list starting at position 4. Here my code:
string sql = "select * from MyTabla";
SqlCommand cm = new SqlCommand(sql, con);
SqlDataReader reader = cm.ExecuteReader();
while (reader.Read())
{
array.Add(Convert.ToString(reader["Cantidad"]));
}
string valor= "45";
if (array.Contains(valor))
{
int indice = array.IndexOf(valor);
}
foreach (string item in array)
{
//imprimir los valores del array apartir del valor de la variable indice
}
You can replace the
foreach
with afor
to be able to access through the index.If you want to start from a particular index you could use the Skip function
Or use a
for
Add this reference:
Once done you can use this code:
Hope this can help you,
Greetings.