Monday, March 18, 2013

c# split list into sub lists

public static List<List<T>> Split<T>(List<T> source)
        {
            return source
                .Select((x, i) => new { Index = i, Value = x })
                .GroupBy(x => x.Index / 4)
                .Select(x => x.Select(v => v.Value).ToList())
                .ToList();
        }

Read file content with File reader

 using (StreamReader stream = File.OpenText(PathOfFile))
            {
                string fileContentsDatas = stream.ReadToEnd();
}