troubleshooting Question

Can I populate a class from LINQ query?

Avatar of anderdw2
anderdw2Flag for United States of America asked on
.NET ProgrammingC#
13 Comments1 Solution565 ViewsLast Modified:
I have a LINQ query on a csv reader.  I have a class that I would like to populate with the query results.

I can't pass the class in the creation, like commented out below asmy csv has multiple types of data.  So, I look at column 4 to see which type it is and I'd like to create a class from that query, then do another query for each different column 4.  Each would point to a new class after the query.

//TextFileReader<CornSilage> csvReader = new TextFileReader<CornSilage>(thisFile, ",");
TextFileReader csvReader = new TextFileReader(thisFile, ",");
                            //TextFileReader<CornSilage> csvReader = new TextFileReader<CornSilage>(thisFile, ",");
                            var thisQuery = from it2 in csvReader
                                            where it2[4].Equals("Corn Silage")
                                            select new CornSilage {};
                            foreach (var x2 in thisQuery)
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros