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))

{

     ……

}

Ref: https://msdn.microsoft.com/en-us/library/ms132403(v=vs.110).aspx

Take<T>

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


Read

%d bloggers like this: