Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6195157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:25:10+00:00 2026-05-24T03:25:10+00:00

I have a sample CSV file as follows 1,A 2,B 3,C Code: var query

  • 0

I have a sample CSV file as follows

  1. 1,A
  2. 2,B
  3. 3,C

Code:

var query = File.ReadAllLines("test.txt")
            .Select(record => record.Split(','))
            .Select(tokens => new { clearNum = tokens[0], MPID = tokens[1] });

foreach (var item in query)
{
    Console.WriteLine("{0}, {1}", item.clearNum, item.MPID);
}

I am able to print the items.

I need to send the output of LINQ query to LIST

public class icSASList
{
public string ClearNum { get; set; }
public string MPID { get; set; }
}

List clearList = new List;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:25:11+00:00Added an answer on May 24, 2026 at 3:25 am

    After considering the accepted answer, I’d like to suggest a solution that requires less object initializations. If the list is large, this will make a difference.

    var query = File.ReadAllLines("test.txt")
    .Select(record => record.Split(','))
    .Select(tokens => new icSASList(){ ClearNum = tokens[0], MPID = tokens[1] }); 
    
    var clearList = query.ToList();
    

    Oh, yeah, using record.Split(',') is naive – it’s normally allowed to have commas in ” (quoted) fields, which will break your program. Better use something like http://www.filehelpers.com/.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have CSV file with sample data in this form : 220 30 255
I have a csv file with following sample data. o-option(alphabetical) v-value(numerical) number1,o1,v1,o2,v2,o3,v3,o4,v4,o5,v5,o6,v6 number2,o1,v11,o2,v22,o3,v33,o44,v44,o5,v55,o6,v66 and
I have a CSV file that I'd like to split up based on a
I have followed the sample code below to upload a zip file in the
I have following sample CSV file rc,u,s,ui,gh m,1,8,0,12 n,3,0,0,7 d,1,1,8,0 I want to read
I have this code which extracts data from a csv file and then reformats
I have a simple report that I want to export to a CSV file.
I have another csv file where I am trying to do a simple word
Does anyone have sample code to copy open (in-use and locked by another program)
Does anyone have sample code, or a tutorial which demonstrates how to use Grappa

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.