How does Array.ForEach() compare to standard for loop in C#?
Posted
by DaveN59
on Stack Overflow
See other posts from Stack Overflow
or by DaveN59
Published on 2010-03-25T19:01:27Z
Indexed on
2010/03/25
19:03 UTC
Read the original article
Hit count: 117
I pine for the days when, as a C programmer, I could type:
memset( byte_array, '0xFF' );
and get a byte array filled with 'FF' characters. So, I have been looking for a replacement for this:
for (int i=0; i < byteArray.Length; i++)
{
byteArray[i] = 0xFF;
}
Lately, I have been using some of the new C# features and have been using this approach instead:
Array.ForEach<byte>(byteArray, b => b = 0xFF);
Granted, the second approach seems cleaner and is easier on the eye, but how does the performance compare to using the first approach? Am I introducing needless overhead by using Linq and generics?
Thanks, Dave
© Stack Overflow or respective owner