Popular Posts
Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... File operation at SMB / UNC (network neighborhood) import java.io.IOException; import java.io.OutputStreamWriter; import jcifs.Config; import jcifs.smb.SmbFile; import jcifs.smb.SmbFileOutpu... Add a event to Outlook calendar dymatically protected void btnAddEventToOutlook_Click(object sender, EventArgs e) {     Response.Clear();     Response.AddHeader("content-dispositi...
Stats
Linq: Loop extension
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Linq
{
    public static class GenericEachExtension
    {
        public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (T t in source)
            {
                action.Invoke(t);
            }
            return source;
        }

        public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Func<T, bool> action)
        {
            foreach (T t in source)
            {
                if (!action.Invoke(t)) break;
            }
            return source;
        }

        public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Action<T, int> action)
        {
            int i = 0;
            foreach (T t in source)
            {
                action.Invoke(t, i);
                i++;
            }
            return source;
        }

        public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Func<T, int, bool> action)
        {
            int i = 0;
            foreach (T t in source)
            {
                if (!action.Invoke(t, i)) break;
                i++;
            }
            return source;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Collections
{
    public static class EachExtension
    {
        public static IEnumerable Each<T>(this IEnumerable source, Action<T> action)
        {
            foreach (T t in source)
            {
                action.Invoke(t);
            }
            return source;
        }

        public static IEnumerable Each<T>(this IEnumerable source, Func<T, bool> action)
        {
            foreach (T t in source)
            {
                if (!action.Invoke(t)) break;
            }
            return source;
        }

        public static IEnumerable Each<T>(this IEnumerable source, Action<T, int> action)
        {
            int i = 0;
            foreach (T t in source)
            {
                action.Invoke(t, i);
                i++;
            }
            return source;
        }

        public static IEnumerable Each<T>(this IEnumerable source, Func<T, int, bool> action)
        {
            int i = 0;
            foreach (T t in source)
            {
                if (!action.Invoke(t, i)) break;
                i++;
            }
            return source;
        }

        public static IEnumerable Each(this IEnumerable source, Action<object> action)
        {
            foreach (object t in source)
            {
                action.Invoke(t);
            }
            return source;
        }

        public static IEnumerable Each(this IEnumerable source, Func<object, bool> action)
        {
            foreach (object t in source)
            {
                if (!action.Invoke(t)) break;
            }
            return source;
        }

        public static IEnumerable Each(this IEnumerable source, Action<object, int> action)
        {
            int i = 0;
            foreach (object t in source)
            {
                action.Invoke(t, i);
                i++;
            }
            return source;
        }

        public static IEnumerable Each(this IEnumerable source, Func<object, int, bool> action)
        {
            int i = 0;
            foreach (object t in source)
            {
                if (!action.Invoke(t, i)) break;
                i++;
            }
            return source;
        }
    }
}