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 9148855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:23:13+00:00 2026-06-17T11:23:13+00:00

Im reading csv files into a list. since each file contains many lines and

  • 0

Im reading csv files into a list. since each file contains many lines and time-consuming to read, I only need to check the first 100 lines for each file. How can I have Linq to only read first 100 lines and then continue to the next file?

For(i=0;i<10;i++)
     line_list = (from line in File.ReadLines(files[i])
                  let field = line.Split(',')
                  where field[2] == "Apple" && !field[3].Contains("Banana")
                  select field).ToList();
  • 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-06-17T11:23:14+00:00Added an answer on June 17, 2026 at 11:23 am

    You can use Enumerable.Take to take only the first 100 lines:

    var first100Lines = File.ReadLines(path).Take(100);
    

    for what it’s worth, here the all in one:

    List<List<string[]>> allFileLineColumns = files
        .Select(fPath => 
            File.ReadLines(fPath)
                .Take(100)
                .Select(l => new { Line=l, Cols=l.Split(',') })
                .Where(x => x.Cols.Length >= 4 && x.Cols[2] == "Apple" && !x.Cols[3].Contains("Banana"))
                .Select(x => x.Cols)
                .ToList()
        ).ToList();
    

    Although i would split it into multiple parts to increase readability.

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

Sidebar

Related Questions

i am reading a csv file into a list of a list in python.
There are many libraries for reading/writing/appending text from/into a csv file in java. Which
I've got a bunch of csv files that I'm reading into R and including
I am reading in large csv file using read.csv . Several websites suggest using
I am reading a csv file into a variable data like this: def get_file(start_file):
i am reading a csv file into a data: def get_file(start_file): #opens original file,
I am reading two csv files containg a set of attributes File 1 attributes
I'm trying to read a csv file into either an ArrayList or a String
I have been writing an implementation for reading a .csv data file into C#
I am reading .csv file through PHP using fgetcsv(). Now I am able to

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.