Created
February 9, 2019 21:07
-
-
Save 8SheldonS8/1d35fc79bade650ca8c4c0a3020b4c80 to your computer and use it in GitHub Desktop.
LinqToCsv_Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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