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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:02:22+00:00 2026-05-31T05:02:22+00:00

Given data returned from: public IEnumerable<IEnumerable<string>> ReadFile(string filename) { List<List<string>> items; // Read entire

  • 0

Given data returned from:

public IEnumerable<IEnumerable<string>> ReadFile(string filename)
{
   List<List<string>> items;
   // Read entire file content into items.
   ...
   return items;
 }

How can I retrieve/return a specific column?

public IEnumerable<string> GetColumnAtIndex(IEnumerable<IEnumerable<string>> items, int index)
{
    // THIS IS NOT WORKING...
    return (from row in items
              select row.ElementAt(index)).ToList();
}

Example intended use:

var items = ReadFile(@"testdata.csv");
var singleColumn = GetColumnAtIndex(items, 2);
  • 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-31T05:02:23+00:00Added an answer on May 31, 2026 at 5:02 am

    Having just read your comment that your problem is that you are getting an ArgumentOutOfRangeException then the most likely cause for that is that some of the List<string> objects that make up your rows do not have enough elements to have somethign in the column you have asked for.

    For example an empty row might parse to an empty List<string> or one with only a "" at position 0. If you were to try to get all the entries at position 5 then whjen it got to this row it would throw that exception.

    If you have List<List<string>> items and you want to get the List<string> in the 0th position you can do this:

    List<string> innerList = items[0];
    

    If you want the item that is in the 0th position of that list you can just do

    string item = items[0][0];
    

    You don’t need to use linq unless I have missed what you are trying to do.

    Oh, I’ve realised you might want the nth item from the inner list for every one of the outer lists… In that case what you have should work and indeed does in my test case:

    List<List<string>> foo = new List<List<string>>(){new List<string>(){"1","2","3","4","5"},new List<string>(){"6","7","8","9","0"}};
    var output = (from row in foo
              select row.ElementAt(2)).ToList();
    output.Dump();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to read data from a webpage : public class
Given a data stream of continuously arriving items containing a timestamp and text (e.g.
I am using the excellent jTemplates plugin to generate content. Given a data object
In my Android application I need to read a large amount of data from
Given this data set: ID Name City Birthyear 1 Egon Spengler New York 1957
Given a data structure (e.g. a hash of hashes), what's the clean/recommended way to
Given a data set like this; +-----+---------------------+--------+ | id | date | result |
I'm being given a data source weekly that I'm going to parse and put
I know you could make a helper pretty easily given the data. So, if
Hey guys, given a data set in plain text such as the following: ==Events==

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.