Friday November 27th

Thursday November 26th

Wednesday November 25th

Create elegant code with Action delegate and List.ForEach method

Small example of how to use Action delegate to perform some action on all elements of a collection.


wow crazy tip. good post!

Cool stuff! I like it!

You don't even need a delegate to do this sort of thing. Just use a method that has the same signature. For example, I use Regex' IsMatch method all the time with the Filter<T> method of Array.

Regex foo = new Regex(".*Lol.*");

string[] linesThatContainLol = Array.Filter<string>(sourceArray, foo.IsMatch);

1) The tip doesn't specifically cast to the Action delegate, which is what I was implying above
2) I hate emoticons. They must die. Die emoticons die.

@yesthatmcgurk: Nice one. I am kinda amazed this level of tips gets that many kicks but fair enough, the comments make up for it. Here's another one...

string[] a = { "1", "2" };
int[] b = Array.ConvertAll<string,int>(a, int.Parse);

To have automatic emoticon functionality where code may be potentially posted is indeed very wrong.

We're working on this.

the following code cures cancer

Commenting on Stories is limited for now and will open up to those recommended by the community. Learn how
Loading DotNetKicks...
brought to you by the Kicks Network