Skip to content

Instantly share code, notes, and snippets.

@kamiyaowl
Created April 5, 2014 15:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamiyaowl/9993394 to your computer and use it in GitHub Desktop.
Save kamiyaowl/9993394 to your computer and use it in GitHub Desktop.
c# read csv
30,12,55,13,32,7,25,44,14,36,20,22,2,10,46,29,33,59,38,0,74,61,72,34,35,6,78,5,23,28,1,4,93,3,42,82,17,19,8,66,51,65,26,11,54,31,16,9,39,57,56,43,83,62,99,18,75,68,49,89,21,48,60,50,47,71,69,91,15,58,94,92,90,52,41,79,64,37,27,98,85,73,40,81,80,95,77,67,97,86,53,70,24,76,84,96,63,45,88,87,
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections.Generic;
static class Extension {
public static IEnumerable<int> CreateSource(this string[] src) {
return src.SelectMany(x => x.Split(',')).Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => int.Parse(x));
}
public static void ForEach<T>(this IEnumerable<T> src, Action<T> f) {
foreach (var s in src)
f(s);
}
static void Main() {
File.ReadAllLines("Src.csv").CreateSource().ForEach(x => Console.Write("{0},",x));
}
}
30 12 55 13 32 7 25 44 14 36
20 22 2 10 46 29 33 59 38 0
74 61 72 34 35 6 78 5 23 28
1 4 93 3 42 82 17 19 8 66
51 65 26 11 54 31 16 9 39 57
56 43 83 62 99 18 75 68 49 89
21 48 60 50 47 71 69 91 15 58
94 92 90 52 41 79 64 37 27 98
85 73 40 81 80 95 77 67 97 86
53 70 24 76 84 96 63 45 88 87
@xlimit91
Copy link

xlimit91 commented Apr 7, 2017

thank you, this was helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment