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

  • SEARCH
  • Home
  • 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 3627540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:54:05+00:00 2026-05-18T23:54:05+00:00

I know I have asked this question in a different manner earlier today but

  • 0

I know I have asked this question in a different manner earlier today but I have refined my needs a little better.

Given the following csv file where the first column is the title and there could be any number of columns;

year,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017
income,1000,1500,2000,2100,2100,2100,2100,2100,2100,2100
dividends,100,200,300,300,300,300,300,300,300,300
net profit,1100,1700,2300,2400,2400,2400,2400,2400,2400,2400
expenses,500,600,500,400,400,400,400,400,400,400
profit,600,1100,1800,2000,2000,2000,2000,2000,2000,2000

How do I select the profit value for a given year? So I may provide a year of say 2011 and expect to get the profit value of 2000 back.

At the moment I have this which shows the profit value for each year but ideally I’d like to specify the year and get the profit value;

        var data = File.ReadAllLines(fileName)
            .Select( 
                l => {
                    var split = l.Split(",".ToCharArray());
                    return split;
                }
            );

        var profit = (from p in data where p[0] == profitFieldName select p).SingleOrDefault();
        var years = (from p in data where p[0] == yearFieldName select p).FirstOrDefault();
        int columnCount = years.Count() ;

        for (int t = 1; t < columnCount; t++)
            Console.WriteLine("{0} : ${1}", years[t], profit[t]);
  • 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-18T23:54:06+00:00Added an answer on May 18, 2026 at 11:54 pm

    I’ve already answered this once today, but this answer is a little more fleshed out and hopefully clearer.

    string rowName = "profit";
    string year = "2011";
    
    var yearRow = data.First();
    var yearIndex = Array.IndexOf(yearRow, year);
    
    // get your 'profits' row, or whatever row you want
    var row = data.Single(d => d[0] == rowName);
    
    // return the appropriate index for that row.
    return row[yearIndex];
    

    This works for me.

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

Sidebar

Related Questions

I know questions of this kind have been asked before, but my situation differs
I know there have been a few threads on this before, but I have
this question can create a misunderstanding: I know I have to use CSS to
I don't know if I have all the information needed to phrase this question
I know I have already answered a similar question ( Running Batch File in
(If anything here needs clarification/ more detail please let me know.) I have an
I know I could have an attribute but that's more work than I want
I know that I have to use: rdtsc. The measured function is deterministic but
I know there have been questions in the past about SQL 2005 versus Lucene.NET
OK, I know there have already been questions about getting started with TDD ..

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.