Let's say i have a fairly large 2D array (a bit over 2 million entries) containing some basic objects (in my case, it's a 2d array of pixel objects).
My goal is to loop through every item in the 2D array and do some basic modification to the object, such as changing one of its properties or something.
Currently i am just looping through it with a foreach and accessing each object via the loop.
This takes around 2 seconds to accomplish with C#.
I am wondering if there is a faster way for me to accomplish this. I wrote some similar code in c++ a long time ago and it performed almost instantaneously, so i'm a bit disappointed that performance has suffered a bit in C#.
Can i somehow speed things up with asynchronous code perhaps? Am i doing something in a less-than-optimal way?
foreach (Pixel p in my2Darray.Pixels) //this is a 2d array but we can still just loop through it with a single for loop
{
p.SetColor(Color.red);
}