Directory Freebies VS CheatSheet Forum

RSS

Email

Translate

Home About Archive Privacy Contact Advertise Write for Dev102
Posted by Amit on Dec 24th, 2008 | Filed under .Net, C# | 6 Comments

Hi all

 

I was into filtering items lately :) and I have decided to write about some of the techniques out there starting with the old

 

The good old Foreach

Well we have all used this before once you get a list in your hands just iterate through all the items and select the ones you want:

   1: private static List<int> TheOld_FilterPositiveItems(List<int> t)
   2: {
   3:     List<int> ret = new List<int>();
   4:     foreach (int i in t)
   5:     {
   6:         if (i > 0)
   7:         {
   8:             ret.Add(i);
   9:         }
  10:     }
  11:     return ret;
  12: }

I hope you are not using this method. As there are other good methods like this one:

 


Continue Reading...
Write Article for Dev102

Write for Dev102!

We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution

Learn More