I have an array where the index starts at 0. I am attempting to determine how I find specific items in array.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
I only want 2,6,10,14. If it wasn’t a 0-index array I could do a modulus%3 on the index and get what I want but I cannot figure out how to do it.
string[] arr = new string[16];
arr[0] = "data";
arr[1] = "data";
arr[2] = "data";
arr[3] = "data";
arr[4] = "data";
arr[5] = "data";
arr[6] = "data";
arr[7] = "data";
arr[8] = "data";
arr[9] = "data";
arr[10] = "data";
arr[11] = "data";
arr[12] = "data";
arr[13] = "data";
arr[14] = "data";
arr[15] = "data";
for (int i = 0; i < arr.Length; ++i)
{
if (i % 3 == 0)
{
Console.WriteLine(arr[i]);
Console.ReadLine();
}
}
Console.ReadLine();
This of course doesn’t work for me and I’ve tried manipulating ‘i’ but I just haven’t had enough coffee yet today to get it to work.
It looks like you want