Skip to content

Instantly share code, notes, and snippets.

@8SheldonS8
Created February 9, 2019 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 8SheldonS8/1d35fc79bade650ca8c4c0a3020b4c80 to your computer and use it in GitHub Desktop.
Save 8SheldonS8/1d35fc79bade650ca8c4c0a3020b4c80 to your computer and use it in GitHub Desktop.
LinqToCsv_Example
using System;
using System.Collections.Generic;
using LINQtoCSV;
namespace linq2csv
{
class Program
{
static void Main(string[] args)
{
CsvFileDescription fileDescription = new CsvFileDescription
{
SeparatorChar = ',',
FirstLineHasColumnNames = true
};
CsvContext csvContext = new CsvContext();
IEnumerable<AColor> theColors = csvContext.Read<AColor>("somecolors.csv", fileDescription);
foreach (AColor aColor in theColors)
{
Console.WriteLine(String.Format("{0} has a hex of {1} and RGB of {2}", aColor.name, aColor.hex, aColor.rgb.Replace("_",",")));
}
}
}
public class AColor
{
public string name { get; set; }
public string hex { get; set; }
public string rgb { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment