(edit: Slight tidy of the code.)
Using foreach like this works fine.
var a = new List<Vector2>();
a.ForEach(delegate(Vector2 b) {
b.Normalize(); });
The following however causes “No overload for method ‘ForEach’ takes 1 arguments”.
byte[,,] a = new byte[2, 10, 10];
a.ForEach(delegate(byte b) {
b = 1; });
raw arrays have much less instance methods than generic collections because they are not templated. These methods, such as
ForEach()orSort()are usually implemented as static methods which are themselves templated.In this case,
Array.Foreach(a, action)will do the trick for the array.Of course, the classical
foreach(var b in a)would work for both List and Array since it only requires an enumerator.However:
(b=1)won’t work. Because you receive a value, not a reference.