Skip to content

Instantly share code, notes, and snippets.

@dalager
Created February 23, 2012 14:25
Show Gist options
  • Save dalager/1893063 to your computer and use it in GitHub Desktop.
Save dalager/1893063 to your computer and use it in GitHub Desktop.
Kolonnesplitter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var strings = new List<string>();
for (int i = 0; i < 32; i++)
{
strings.Add(i+1+"_"+Guid.NewGuid());
}
var prcolumn = strings.Count/3; // 10
var leftover = strings.Count%prcolumn; // 2
var firstcolcount = prcolumn + (leftover > 0 ? 1 : 0); // antal i første kolonne
var col1 = strings.Take(firstcolcount);
var secondcolcount = prcolumn + (leftover > 1 ? 1 : 0);
var col2 = strings.Skip(firstcolcount).Take(secondcolcount);
var col3 = strings.Skip(firstcolcount + secondcolcount).Take(prcolumn);
Console.Out.WriteLine("COL 1");
foreach (var s in col1)
{
Console.Out.WriteLine(s);
}
Console.Out.WriteLine("");
Console.Out.WriteLine("COL 2");
foreach (var s in col2)
{
Console.Out.WriteLine(s);
}
Console.Out.WriteLine("");
Console.Out.WriteLine("COL 3");
foreach (var s in col3)
{
Console.Out.WriteLine(s);
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment