limit the iterations in foreach loop c#

Leave a comment

Hi All,

Sometimes there will be a huge data to loop through but you need to check for few iterations only say 10. In that case items collections in foreach loop contains a built in method to limit the iterations.TAKE

foreach (Object o in collection.Items.Take(10))






Returns a specified number of contiguous elements from the start of a sequence. (Defined by Enumerable.)


Five fascinating revelations from ‘Becoming Steve Jobs’

Leave a comment


%d bloggers like this: