score:2
If your schema is really this simply, it could be accomplished in a minimal amount of code using Tuple
and HashSet<T>
.
The basic strategy in any case is to create a data structure to track what you have seen and use that to determine what to output. A dictionary tracking counts could be used as well. However, as a means of memory versus code trade-off, I've chosen to use two sets instead of one dictionary:
// 1. Data structure to track items we've seen
var found = new HashSet<Tuple<string, int>>();
// 2. Data structure to track items we should output
var output = new HashSet<Tuple<string, int>>();
// 3. Loop over the input data, storing it into `found`
using (var input = File.OpenText(path))
{
string line;
while (null != (line = input.ReadLine()))
{
// 4. Do your CSV parsing
var parts = line.Split(','); // <- need better CSV parsing
var item = Tuple.Create(parts[0], Int32.Parse(parts[1]));
// 5. Track items we've found and those we should output
// NB: HashSet.Add returns `false` if it already exists,
// so we use that as our criteria to mark the item for output
if (!found.Add(item)) output.Add(item);
}
}
// 6. Output the items
// NB: you could put this in the main loop and borrow the same strategy
// we used for `found` to determine when to output an item so that only
// one pass is needed to read and write the data.
score:1
Without knowing the exact specifics, the first step I would take is looking into a Linq To CVS library, such as this...
http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library
Source: stackoverflow.com
Related Query
- C# query and comparing entries in a CSV file
- How to query and extract data from CSV file directly by LINQ
- Extracting data from CSV file (fusion table and kml workaround)
- EF Code First comparing null values generates strange query
- Avoid extra loop and could not find implementation of query pattern for source type int Select not found
- How to I read a json file containing array with C# and perform LINQ query on it?
- Code Example for Add DateTime and TimeSpan in EF query
- C# Read and filter CSV file using LINQ
- Comparing positive boolean result to true and false in LINQ query
- Using LINQ to query huge CSV and Excel
- Creating a LINQ query that will include all entries from the current week excluding today and yestreday
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Why are stored procedures, functions, and views put into a .dbml file instead of the code file?
- Joining a CSV file to query results
- Linq to CSV : Convert data to .CSV file and return file from an action without saving file on the server
- CsvHelper and querying a large csv file in parallel
- Comparing two csv files by column and value and displaying line numbers of differing values
- Entity Framework - complex query - and CSV export
- LINQ query to generate XML type output on console windows and XML file
- Query XML using linq and comparing two variable
- C# Comparing two sorted lists and outputting to a file
- EF Code First Query and assign without savechanges
- LINQ-TO-SQL query not working with CSV file
- How to sort the second column of csv file using LINQ query in Power shell
- How to read an uploaded CSV file in ASP.NET and skip the first line?
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How to assign LINQ Query to a variable and then use it later in the code
- Using C#, how can we pull attribute values from an XML Schema file and output that onto a CSV file?
- LINQ query on dotnet code and how concat will work here
- error :Could not find an implementation of query for source type datatable and join not found while trying to join two datatables
More Query from same tag
- How to LINQ Query Code First generated EF6 hierarchical entities (entities within entities)?
- Combine several similar SELECT-expressions into a single expression
- Passing null parameters into LINQ where clause
- Using Linq to iterate groups and change property with condition
- Creating hierarchical JSON result from multiple tables using linq expression
- Converting JSON array to JSON Object
- Remove errors of type Required from ModelState
- Including a Method class inside an Expression
- Excel Import : Data not being read if column has different data formats in MVC C# using linq
- how to get the linq list having Ids from IEnumerable<Object>
- determining differences between generic lists
- Create DateTime within LINQ query
- What does ExpressionVisitor.Visit<T> Do?
- Limit collection by enum using lambda
- Simple Linq query has duplicated join against same table?
- ASP. NET MVC3 - How to display all Comments in Post
- How can I create a JSONPath filter expression to search using contains keyword
- How to cope with an Observable collection of classes
- How to modify an object depends on join condition in linq
- How to group by day of week using linq
- Is it possible to create C# language modifications as did LINQ?
- where clause subquery in LINQ
- LINQ to Entities does not recognize the method Boolean IsAssignableFrom
- How can I implement it by Linq?
- How do I refactor a ReadLine loop to Linq
- VB.Net LINQ Get Field Names when no rows
- OData V3 exclude property
- Why does this LINQ statement throw a timeout error?
- Delete subjects which isn't selected anymore
- condition in function parameter