ForEach

S

shapper

Hello,

I got the following code from an online example:

public static void Repeater<T>(this HtmlHelper html,
IEnumerable<T> items, string className, string classNameAlt, Action<T,
string> render) {
int i = 0;
items.ForEach(item => {
render(item, (i++ % 2 == 0) ? className: classNameAlt
});
}

ForEach is not recognized.
I imported System, System.Collections, System.Collections.Generic,
System.Linq, ...

Am I missing something?

Thanks,
Miguel
 
M

Martin Honnen

shapper said:
I got the following code from an online example:

public static void Repeater<T>(this HtmlHelper html,
IEnumerable<T> items, string className, string classNameAlt, Action<T,
string> render) {
int i = 0;
items.ForEach(item => {
render(item, (i++ % 2 == 0) ? className: classNameAlt
});
}

ForEach is not recognized.
I imported System, System.Collections, System.Collections.Generic,
System.Linq, ...

Am I missing something?

List<T> has a ForEach method so you could use
items.ToList().ForEach(...)
 
M

Martin Honnen

shapper said:
I got the following code from an online example:

public static void Repeater<T>(this HtmlHelper html,
IEnumerable<T> items, string className, string classNameAlt, Action<T,
string> render) {
int i = 0;
items.ForEach(item => {
render(item, (i++ % 2 == 0) ? className: classNameAlt
});
}

ForEach is not recognized.
I imported System, System.Collections, System.Collections.Generic,
System.Linq, ...

Am I missing something?

List<T> has a ForEach method so you could use
items.ToList().ForEach(...)
 
S

shapper

S

shapper

C

Cor Ligthert[MVP]

Pete,

And that is what I have against for the programmer clever extension methods
(which is often only for him to proof how clever he is).

As soon as a program needs maintenance even the original programmer does
often not know anymore what clever extensions he has made.

This does not mean that I am against any usable method, however, keep always
maintenance in mind.

Cor


Don't understand me wrong, I write to that
 
C

Cor Ligthert[MVP]

Pete,

And that is what I have against for the programmer clever extension methods
(which is often only for him to proof how clever he is).

As soon as a program needs maintenance even the original programmer does
often not know anymore what clever extensions he has made.

This does not mean that I am against any usable method, however, keep always
maintenance in mind.

Cor


Don't understand me wrong, I write to that
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top